結果

問題 No.593 4進FizzBuzz
ユーザー taotao54321
提出日時 2019-12-13 18:41:12
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 14,280 ms
コンパイル使用メモリ 379,600 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-06-27 09:20:54
合計ジャッジ時間 15,320 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 15 WA * 16
権限があれば一括ダウンロードができます

ソースコード

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