結果

問題 No.784 「,(カンマ)」
コンテスト
ユーザー nao22b
提出日時 2019-04-13 17:19:22
言語 Elixir
(1.19.5)
コンパイル:
elixirc _filename_
実行:
elixir -e Main.main
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 456 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 782 ms
コンパイル使用メモリ 72,316 KB
実行使用メモリ 63,940 KB
最終ジャッジ日時 2026-06-04 14:07:55
合計ジャッジ時間 6,460 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  Main.exs:6: Main.solve/2

ソースコード

diff #
raw source code

defmodule Main do
    def solve("", acc), do: acc

    def solve(s, acc) do
        l = String.at(s, -1)
        ss = String.slice(s, 0..-2)
        ac = append(l, acc, String.length(acc))
        solve(ss, ac)
    end

    def append(l, acc, len) when rem(len, 4) == 3 do
        l <> "," <> acc
    end
    def append(l, acc, _) do
        l <> acc
    end

    def main do
        s = IO.gets("") |> String.trim
        IO.puts solve(s, "")
    end
end
0