27 lines
624 B
Rust
27 lines
624 B
Rust
use std::io;
|
|
use std::io::prelude::*;
|
|
use std::fs::File;
|
|
|
|
fn read_lines(filename: &str) -> io::Result<io::Lines<io::BufReader<File>>> {
|
|
let file = File::open(filename)?;
|
|
Ok(io::BufReader::new(file).lines())
|
|
}
|
|
|
|
fn main() -> Result<(), io::Error> {
|
|
let mut max = 0;
|
|
let mut current = 0;
|
|
|
|
for line in read_lines("input.txt")? {
|
|
let text = line?;
|
|
current = match text.parse::<i32>() {
|
|
Ok(value) => current + value,
|
|
Err(_) => {
|
|
if current > max { max = current; }
|
|
0
|
|
},
|
|
};
|
|
}
|
|
|
|
println!("{}", max);
|
|
Ok(())
|
|
}
|