Created
January 12, 2026 19:58
-
-
Save icub3d/d0844409745b59462ddf4e82a22fef91 to your computer and use it in GitHub Desktop.
Kattis drinkingsong
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::{Read, stdin}; | |
| fn main() { | |
| let mut s = String::new(); | |
| stdin().read_to_string(&mut s).unwrap(); | |
| let mut ss = s.lines(); | |
| let n = ss.next().unwrap().parse::<usize>().unwrap(); | |
| let d = ss.next().unwrap(); | |
| let f = |c: usize| match c { | |
| 0 => format!("no more bottles of {d}"), | |
| 1 => format!("1 bottle of {d}"), | |
| _ => format!("{c} bottles of {d}"), | |
| }; | |
| for i in (1..=n).rev() { | |
| let (cur, next) = (f(i), f(i - 1)); | |
| let p = if i == 1 { "it" } else { "one" }; | |
| println!("{cur} on the wall, {cur}."); | |
| print!("Take {p} down, pass it around, {next}"); | |
| if i > 1 { | |
| println!(" on the wall."); | |
| println!(); | |
| } else { | |
| println!("."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment