結果

問題 No.9002 FizzBuzz(テスト用)
ユーザー yukiccoyukicco
提出日時 2018-11-16 22:50:25
言語 Elixir
(1.16.2)
結果
AC  
実行時間 638 ms / 5,000 ms
コード長 712 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 55,844 KB
実行使用メモリ 50,516 KB
最終ジャッジ日時 2023-08-29 23:01:47
合計ジャッジ時間 4,995 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 632 ms
49,788 KB
testcase_01 AC 628 ms
49,692 KB
testcase_02 AC 638 ms
50,516 KB
testcase_03 AC 638 ms
49,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
    def getsAll(device \\ :stdio, prompt), do: getsAll(device, prompt, "")
    defp getsAll(device, prompt, input) do
        x = IO.gets(device, prompt)
        case x do
            {:error, _} -> x
            :eof -> input
            _ -> getsAll(device, prompt, input <> x)
        end
    end
    def fizzbuzz(n) do
        cond do
            rem(n, 3) == 0 and rem(n, 5) == 0 -> "FizzBuzz"
            rem(n, 3) == 0 -> "Fizz"
            rem(n, 5) == 0 -> "Buzz"
            true -> n
        end
    end
    def main do

        inputs = getsAll(nil) |> String.split

        n = inputs |> Enum.at(0) |> String.to_integer

        for x <- 1..n, do: IO.puts fizzbuzz(x)

    end
end
0