結果

問題 No.593 4進FizzBuzz
ユーザー taotao54321taotao54321
提出日時 2019-12-13 18:45:18
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 3,850 ms
コンパイル使用メモリ 133,344 KB
実行使用メモリ 11,852 KB
最終ジャッジ日時 2023-09-09 17:08:53
合計ジャッジ時間 7,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 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,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,380 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,824 KB
testcase_17 AC 13 ms
11,736 KB
testcase_18 AC 13 ms
11,828 KB
testcase_19 WA -
testcase_20 AC 13 ms
11,732 KB
testcase_21 AC 13 ms
11,852 KB
testcase_22 WA -
testcase_23 AC 13 ms
11,820 KB
testcase_24 AC 14 ms
11,828 KB
testcase_25 AC 13 ms
11,752 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 13 ms
11,804 KB
testcase_29 WA -
testcase_30 AC 13 ms
11,776 KB
testcase_31 AC 13 ms
11,776 KB
testcase_32 AC 13 ms
11,820 KB
testcase_33 WA -
testcase_34 AC 13 ms
11,812 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 }) % 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