結果

問題 No.9002 FizzBuzz(テスト用)
ユーザー YoshihitoYoshihito
提出日時 2019-11-15 18:13:30
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 851 bytes
コンパイル時間 1,180 ms
コンパイル使用メモリ 176,968 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-25 03:41:47
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io;
use std::io::{Stdin, BufRead};

struct Input {
    n: i32,
}

fn main() {
    let mut stdin = io::stdin();
    let input = read_input(&mut stdin);
    solve(input);
}

fn read_input(stdin: &mut Stdin) -> Input {
    let mut lock = stdin.lock();

    let mut s = String::new();
    lock.read_line(&mut s).expect("can't read 1st line.");
    let n = s.trim_end().parse::<i32>().expect("can't parse as i32.");
    Input { n }
}

fn solve(input: Input) {
    for n in 1..=input.n {
        println!("{}", fizz_buzz(n));
    }
}

fn fizz_buzz(n: i32) -> String {
    let fizz = if n % 3 == 0 { Some("Fizz") } else { None };
    let buzz = if n % 5 == 0 { Some("Buzz") } else { None };

    match (fizz, buzz) {
        (None, None) => n.to_string(),
        _ => format!("{}{}", fizz.unwrap_or_else(|| ""), buzz.unwrap_or_else(|| "")),
    }
}
0