-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoddmanout.rs
33 lines (24 loc) · 914 Bytes
/
oddmanout.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::io::{self};
use std::collections::HashMap;
fn main() {
let input = io::stdin();
let mut input_buffer = String::from("");
input.read_line(&mut input_buffer).unwrap();
let number_cases: i32 = input_buffer.trim().parse().unwrap();
input_buffer.clear();
for i in 0..number_cases {
input.read_line(&mut input_buffer).unwrap();
input_buffer.clear();
input.read_line(&mut input_buffer).unwrap();
let invite_codes: Vec<i32> = input_buffer.split_whitespace()
.map(|l| l.parse().unwrap()).collect();
let mut hash = HashMap::new();
for code in invite_codes {
*hash.entry(code).or_insert(0) += 1;
}
let singletons: Vec<(i32, i32)> = hash.into_iter()
.filter(|&(_k, v)| v == 1).collect();
println!("Case #{}: {}", i + 1, singletons[0].0);
input_buffer.clear();
}
}