Created
January 20, 2026 16:17
-
-
Save icub3d/dec97c5ed6a13d84be5f8fabf7fe5039 to your computer and use it in GitHub Desktop.
Kattis vote
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().parse::<usize>().unwrap(); | |
| for _ in 0..t { | |
| let n = ss.next().unwrap().parse::<usize>().unwrap(); | |
| let votes = (0..n) | |
| .map(|_| ss.next().unwrap().parse::<usize>().unwrap()) | |
| .collect::<Vec<_>>(); | |
| let sum = votes.iter().sum::<usize>(); | |
| let max = *votes.iter().max().unwrap(); | |
| let winners = votes | |
| .iter() | |
| .enumerate() | |
| .filter(|&(_, v)| *v == max) | |
| .collect::<Vec<_>>(); | |
| if winners.len() > 1 { | |
| println!("no winner"); | |
| continue; | |
| } | |
| if max > sum / 2 { | |
| println!("majority winner {}", winners[0].0 + 1); | |
| } else { | |
| println!("minority winner {}", winners[0].0 + 1); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment