Skip to content

Instantly share code, notes, and snippets.

@ShinyaKato
Created May 21, 2020 11:16
Show Gist options
  • Save ShinyaKato/95b6fa7ab93f31114429c535e4038593 to your computer and use it in GitHub Desktop.
Save ShinyaKato/95b6fa7ab93f31114429c535e4038593 to your computer and use it in GitHub Desktop.
Rust template just taking input from stdin for competitive programming.
use std::io::{self, Read};
macro_rules! input {
($it: expr) => ($it.next().unwrap().parse().unwrap());
($it: expr, $T: ty) => ($it.next().unwrap().parse::<$T>().unwrap());
}
fn main() {
let mut buf = String::new();
io::stdin().read_to_string(&mut buf).unwrap();
let mut it = buf.split_whitespace();
let n: usize = input!(it);
let a: Vec<u64> = (0..n).map(|_| input!(it)).collect();
let mut sum: u64 = 0;
for i in 0..n {
sum += a[i];
}
println!("{}", sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment