結果
| 問題 |
No.9002 FizzBuzz(テスト用)
|
| ユーザー |
|
| 提出日時 | 2019-11-15 18:13:30 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 851 bytes |
| コンパイル時間 | 11,677 ms |
| コンパイル使用メモリ | 400,744 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 23:10:57 |
| 合計ジャッジ時間 | 12,360 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
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(|| "")),
}
}