diff options
Diffstat (limited to '2022/03/b.rs')
| -rw-r--r-- | 2022/03/b.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/2022/03/b.rs b/2022/03/b.rs new file mode 100644 index 0000000..89da764 --- /dev/null +++ b/2022/03/b.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | mod common; | ||
| 2 | use common::*; | ||
| 3 | |||
| 4 | fn get_rep_val(e: &[String; 3]) -> i64 { | ||
| 5 | let mut seen = [[false; 256]; 2]; | ||
| 6 | for i in 0..2 { | ||
| 7 | for c in e[i].chars() { | ||
| 8 | seen[i][c as usize] = true; | ||
| 9 | } | ||
| 10 | } | ||
| 11 | for c in e[2].chars() { | ||
| 12 | if seen[0][c as usize] && seen[1][c as usize] { | ||
| 13 | return value(c); | ||
| 14 | } | ||
| 15 | } | ||
| 16 | panic!("Could not find repeated char"); | ||
| 17 | } | ||
| 18 | |||
| 19 | fn main() { | ||
| 20 | let mut sum = 0; | ||
| 21 | let mut lines: [String; 3] = Default::default(); | ||
| 22 | while std::io::stdin().read_line(&mut lines[0]).unwrap() > 0 { | ||
| 23 | let _ = std::io::stdin().read_line(&mut lines[1]); | ||
| 24 | let _ = std::io::stdin().read_line(&mut lines[2]); | ||
| 25 | sum += get_rep_val(&lines); | ||
| 26 | for l in &mut lines { l.clear(); } | ||
| 27 | } | ||
| 28 | println!("{sum}"); | ||
| 29 | } | ||
