31 lines
729 B
Rust
31 lines
729 B
Rust
|
use std::io;
|
||
|
|
||
|
fn main() -> io::Result<()> {
|
||
|
// read from stdin
|
||
|
let stdin = io::stdin();
|
||
|
let lines = stdin.lines();
|
||
|
|
||
|
let mut elves = Vec::new();
|
||
|
let mut c_sum = 0;
|
||
|
for line in lines {
|
||
|
let content = line.unwrap();
|
||
|
if content.is_empty() {
|
||
|
elves.push(c_sum);
|
||
|
c_sum = 0;
|
||
|
} else {
|
||
|
let new_val = match content.parse::<i32>() {
|
||
|
Ok(v) => v,
|
||
|
Err(_e) =>{ println!("Error parsing input"); 0 }
|
||
|
};
|
||
|
c_sum += new_val;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let result = elves.iter().max();
|
||
|
match result {
|
||
|
Some(result) => println!("{}", result),
|
||
|
None => println!("Empty list")
|
||
|
}
|
||
|
Ok(())
|
||
|
}
|