結果

問題 No.593 4進FizzBuzz
ユーザー taotao54321taotao54321
提出日時 2018-10-08 18:33:15
言語 Rust
(1.77.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 859 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 151,936 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-20 18:39:12
合計ジャッジ時間 2,562 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 0 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 18 ms
19,456 KB
testcase_17 AC 19 ms
19,456 KB
testcase_18 AC 17 ms
19,456 KB
testcase_19 WA -
testcase_20 AC 19 ms
19,456 KB
testcase_21 AC 19 ms
19,456 KB
testcase_22 WA -
testcase_23 AC 19 ms
19,328 KB
testcase_24 AC 19 ms
19,328 KB
testcase_25 AC 20 ms
19,456 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 18 ms
19,456 KB
testcase_29 WA -
testcase_30 AC 19 ms
19,456 KB
testcase_31 AC 19 ms
19,456 KB
testcase_32 AC 19 ms
19,456 KB
testcase_33 WA -
testcase_34 AC 19 ms
19,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io;

fn is_mul3(v: &[char]) -> bool {
    v.iter().fold(0, |sum,c| sum + c.to_digit(4).unwrap()) % 3 == 0
}

fn is_mul5(v: &[char]) -> bool {
    let v: Vec<_> = if v.len() % 2 == 0 {
        v.to_vec()
    }
    else {
        let mut res = vec![];
        res.push('0');
        res.extend_from_slice(v);
        res
    };

    v.chunks(2)
        .map(|v| 4*v[0].to_digit(4).unwrap() + v[1].to_digit(4).unwrap())
        .sum::<u32>() % 5 == 0
}

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let v: Vec<_> = s.trim().chars().collect();

    let mul3 = is_mul3(&v);
    let mul5 = is_mul5(&v);

    if mul3 && mul5 {
        println!("FizzBuzz");
    }
    else if mul3 {
        println!("Fizz");
    }
    else if mul5 {
        println!("Buzz");
    }
    else {
        println!("{}", s);
    }
}
0