結果
| 問題 | No.593 4進FizzBuzz | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-11-10 22:53:36 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 70 ms / 2,000 ms | 
| コード長 | 1,131 bytes | 
| コンパイル時間 | 1,955 ms | 
| コンパイル使用メモリ | 154,040 KB | 
| 実行使用メモリ | 7,956 KB | 
| 最終ジャッジ日時 | 2024-06-12 22:26:03 | 
| 合計ジャッジ時間 | 4,869 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 | 
ソースコード
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);
    reverse(n);
    int k = n.length.to!int;
    int m3, m5;
    foreach (i; 0 .. k) {
        (m3 += n[i] - '0') %= 3;
        if (i & 1) {
            (m5 += n[i] - '0') %= 5;
        }
        else {
            (m5 += (n[i] - '0') * 4) %= 5;
        }
    } 
    debug {
        writefln("m3:%d, m5:%d", m3, m5);
    }
    if (!m3 & !m5) {
        writeln("FizzBuzz");
    }
    else if (!m3) {
        writeln("Fizz");
    }
    else if (!m5) {
        writeln("Buzz");
    }
    else {
        writeln(n.retro());
    }
}
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);
        }
    }
}
            
            
            
        