https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_c
VecはIteratorにするとsumが使えます。
// Sum of N Integers #![allow(non_snake_case)] //////////////////// library //////////////////// 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() } //////////////////// process //////////////////// fn f(A: Vec<i32>) -> i32 { A.iter().sum::<i32>() } fn main() { let _N: usize = read(); let A: Vec<i32> = read_vec(); println!("{}", f(A)) }