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::().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(|| "")), } }