結果

問題 No.593 4進FizzBuzz
ユーザー nanaenanae
提出日時 2017-11-11 12:00:47
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,621 bytes
コンパイル時間 1,922 ms
コンパイル使用メモリ 152,848 KB
実行使用メモリ 9,032 KB
最終ジャッジ日時 2023-09-03 16:51:15
合計ジャッジ時間 5,740 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 35 ms
6,988 KB
testcase_17 AC 34 ms
7,240 KB
testcase_18 AC 35 ms
7,716 KB
testcase_19 AC 73 ms
7,708 KB
testcase_20 AC 34 ms
6,976 KB
testcase_21 AC 34 ms
7,448 KB
testcase_22 AC 74 ms
9,032 KB
testcase_23 AC 34 ms
7,508 KB
testcase_24 AC 35 ms
8,636 KB
testcase_25 AC 33 ms
8,104 KB
testcase_26 AC 73 ms
8,632 KB
testcase_27 AC 73 ms
7,152 KB
testcase_28 AC 35 ms
6,924 KB
testcase_29 AC 73 ms
7,708 KB
testcase_30 AC 34 ms
7,200 KB
testcase_31 AC 35 ms
7,676 KB
testcase_32 AC 35 ms
7,836 KB
testcase_33 AC 74 ms
7,676 KB
testcase_34 AC 35 ms
7,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    char[] n;
    scan(n);

    n.reverse();

    int k = n.length.to!int;

    int m3, m5;

    foreach (i ; 0 .. k) {
        (m3 += n[i] - '0') %= 3;
        (m5 += (n[i] - '0') * (i & 1 ? 1 : 4)) %= 5;
    }

    if (!m3 & !m5) {
        writeln("FizzBuzz");
    }
    else if (!m3) {
        writeln("Fizz");
    }
    else if (!m5) {
        writeln("Buzz");
    }
    else {
        writeln(n.retro());
    }
}



struct Stack(T) {
private:
    int N, peek;
    T[] data;

public:
    this(int size) 
    {
        N = size;
        data = new T[](N);
    }

    bool empty() @property
    {
        return peek == 0;
    }

    bool full() @property
    {
        return peek == N;
    }

    void push(T x) @property
    {
        assert(!full);
        data[peek++] = x;
    }

    void pop() @property
    {
        assert(!empty);
        --peek;
    }

    T top() @property
    {
        return data[peek - 1];
    }

    void clear() @property
    {
        peek = 0;
    }

    int length() @property
    {
        return peek;
    }

}




void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0