結果

問題 No.593 4進FizzBuzz
ユーザー taotao54321taotao54321
提出日時 2019-12-13 18:41:12
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 2,897 ms
コンパイル使用メモリ 137,092 KB
実行使用メモリ 11,856 KB
最終ジャッジ日時 2023-09-09 16:35:39
合計ジャッジ時間 6,452 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
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 13 ms
11,832 KB
testcase_17 WA -
testcase_18 AC 13 ms
11,840 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 12 ms
11,836 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 13 ms
11,660 KB
testcase_31 AC 13 ms
11,832 KB
testcase_32 AC 13 ms
11,832 KB
testcase_33 WA -
testcase_34 AC 13 ms
11,828 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 {
    v.iter().rev().enumerate()
        .fold(0, |sum,(i,c)| sum + (c.to_digit(4).unwrap() as i32) * if i%2==0 { -1 } else { 1 }) == 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