Created
January 29, 2026 20:09
-
-
Save icub3d/f5a39d45aff7e1d7961a7fdd9e1ebd25 to your computer and use it in GitHub Desktop.
Kattis basicprogramming1
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 t = ss | |
| .next() | |
| .unwrap() | |
| .split_once(' ') | |
| .map(|(_, t)| t.parse::<usize>().unwrap()) | |
| .unwrap(); | |
| let a = ss | |
| .next() | |
| .unwrap() | |
| .split_whitespace() | |
| .map(|v| v.parse::<usize>().unwrap()) | |
| .collect::<Vec<_>>(); | |
| match t { | |
| 1 => println!("7"), | |
| 2 => { | |
| if a[0] > a[1] { | |
| println!("Bigger"); | |
| } else if a[0] == a[1] { | |
| println!("Equal"); | |
| } else { | |
| println!("Smaller"); | |
| } | |
| } | |
| 3 => { | |
| let mut f = a[0..3].iter().collect::<Vec<_>>(); | |
| f.sort(); | |
| println!("{}", a[1]); | |
| } | |
| 4 => println!("{}", a.iter().sum::<usize>()), | |
| 5 => println!("{}", a.iter().filter(|&a| a % 2 == 0).sum::<usize>()), | |
| 6 => { | |
| println!( | |
| "{}", | |
| a.iter() | |
| .map(|a| char::from_u32(97 + (a % 26) as u32).unwrap()) | |
| .collect::<String>() | |
| ) | |
| } | |
| 7 => { | |
| let mut i = 0; | |
| let mut seen = vec![false; a.len()]; | |
| loop { | |
| if seen[i] { | |
| println!("Cyclic"); | |
| break; | |
| } | |
| seen[i] = true; | |
| i = a[i]; | |
| if i >= a.len() { | |
| println!("Out"); | |
| break; | |
| } else if i == a.len() - 1 { | |
| println!("Done"); | |
| } | |
| } | |
| } | |
| _ => panic!("unknown"), | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment