Skip to content

Instantly share code, notes, and snippets.

@jmcph4
Created November 20, 2023 00:25
Show Gist options
  • Select an option

  • Save jmcph4/fc74110861ed6d524d3012e22ebcfa76 to your computer and use it in GitHub Desktop.

Select an option

Save jmcph4/fc74110861ed6d524d3012e22ebcfa76 to your computer and use it in GitHub Desktop.
use std::io::{stdin, BufRead};
type Number = i64;
fn main() {
let mut nums: Vec<Number> = vec![];
loop {
if let Some(Ok(line)) = stdin().lock().lines().next() {
if let Ok(num) = line.parse::<Number>() {
nums.push(num);
} else {
break;
}
}
}
if !nums.is_empty() {
println!("{}", nums.iter().sum::<Number>() as f64 / nums.len() as f64);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment