This commit is contained in:
2022-12-01 12:27:20 +00:00
parent afaf4a1ddf
commit 38123f3a00
5 changed files with 48 additions and 2 deletions
+30
View File
@@ -0,0 +1,30 @@
use std::io::{self, BufRead};
fn main() {
let lines = io::stdin().lock().lines().map(|l| l.unwrap());
let mut sum = 0;
let mut max = [0, 0, 0];
for line in lines {
if let Ok(num) = line.parse::<usize>() {
sum += num;
} else {
match (sum > max[0], sum > max[1], sum > max[2]) {
(_, _, true) => {
max.rotate_left(1);
max[2] = sum;
}
(_, true, false) => {
max[0] = max[1];
max[1] = sum;
}
(true, false, false) => {
max[0] = sum;
}
_ => (),
}
sum = 0;
}
}
println!("P1: {} P2: {}", max[2], max.iter().sum::<usize>());
}