https://atcoder.jp/contests/abc236/tasks/abc236_b
enumerateは、本当はindexと値の参照のタプルを返します。
// Who is missing? #![allow(non_snake_case)] fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn who_is_missing(A: &Vec<usize>) -> usize { let N: usize = (A.len() + 1) / 4; let mut B: Vec<i32> = (0..N).map(|_| 0).collect(); for a in A.iter() { B[a-1] += 1 } for (i, &n) in B.iter().enumerate() { if n != 4 { return i + 1 } } return N + 1 } fn main() { let _N: usize = read(); let A = read_vec(); println!("{}", who_is_missing(&A)) }