1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでelixir その333

Posted at

概要

paiza.ioでelixirやってみた。
AtCoder、やってみた。

参考にしたページ

サンプルコード

abc171_c

 
defmodule Abc171C do
  @table ?a..?z
        |> Enum.with_index()
        |> Enum.map(fn {a, b} -> 
            {b, [a] |> List.to_string()} 
        end)
        |> Map.new()
  def main do
    IO.read(:line)
    |> String.trim()
    |> String.to_integer()
    |> solve()
    |> IO.puts()
  end
  def solve(n) when n - 1 < 26 do
    Map.get(@table, n - 1)
  end
  def solve(n) do
    do_solve(n, [])
  end
  defp do_solve(n, acc) when n - 1 < 26 do
    [Map.get(@table, n - 1) | acc]
    |> Enum.join()
  end
  defp do_solve(n, acc) do
    list = Integer.to_charlist(n - 1, 26)
    last = Map.get(@table, [List.last(list)] |> List.to_string() |> String.to_integer(26))
    list
    |> List.delete_at(-1)
    |> List.to_string()
    |> String.to_integer(26)
    |> do_solve([last | acc])
  end
end

Abc171C.main()


実行結果

b

成果物

以上。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?