結果

問題 No.784 「,(カンマ)」
コンテスト
ユーザー gemmaro
提出日時 2020-04-18 08:14:58
言語 Elixir
(1.19.5)
コンパイル:
elixirc _filename_
実行:
elixir -e Main.main
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 649 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 767 ms
コンパイル使用メモリ 73,344 KB
実行使用メモリ 63,800 KB
最終ジャッジ日時 2026-06-04 15:27:23
合計ジャッジ時間 6,406 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
    warning: using single-quoted strings to represent charlists is deprecated.
    Use ~c"" if you indeed want a charlist or use "" instead.
    You may run "mix format --migrate" to change all single-quoted
    strings to use the ~c sigil and fix this warning.
    │
 14 │     |> Enum.map(fn x -> x |> Enum.reverse() |> Enum.concat(',') end)
    │                                                            ~
    │
    └─ Main.exs:14:60

warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  Main.exs:17: Main.solve/1

ソースコード

diff #
raw source code

defmodule Main do
  def main do
    IO.read(:line)
    |> String.trim()
    |> solve
    |> IO.puts()
  end

  def solve(n) do
    n
    |> String.to_charlist()
    |> Enum.reverse()
    |> each_slice_3
    |> Enum.map(fn x -> x |> Enum.reverse() |> Enum.concat(',') end)
    |> Enum.reverse()
    |> Enum.join()
    |> String.slice(0..-2)
  end

  def each_slice_3(list) do
    each_slice_3_rec(list, [])
  end

  def each_slice_3_rec(list, result) do
    case list do
      [a, b, c | d] ->
        each_slice_3_rec(d, result |> Enum.concat([[a, b, c]]))

      [] ->
        result

      l ->
        result |> Enum.concat([l])
    end
  end
end
0