From 8d4017c0da4f6228b35d9f17fdbd65397481f263 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Fri, 2 Dec 2022 23:21:38 +0100 Subject: [PATCH] minor cleanups --- d01.cc | 3 +-- d02.cc | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/d01.cc b/d01.cc index a178e23..8274cd4 100644 --- a/d01.cc +++ b/d01.cc @@ -8,9 +8,8 @@ vector parse() { vector elves; - string line; unsigned elf = 0; - while (getline(cin, line)) { + for (string line; getline(cin, line);) { if (line.empty()) { elves.push_back(elf); elf = 0; diff --git a/d02.cc b/d02.cc index 65bdddc..7e5cf12 100644 --- a/d02.cc +++ b/d02.cc @@ -7,12 +7,11 @@ using namespace std; vector> parse() { vector> input; - string line; - while (getline(cin, line)) { - if (line.size() < 3 || line[1] != ' ') abort(); + for (string line; getline(cin, line);) { + if (line.size() < 3 || line[1] != ' ') throw "parse"; unsigned oppo = line[0] - 'A'; unsigned user = line[2] - 'X'; - if (oppo >= 3 || user >= 3) abort(); + if (oppo >= 3 || user >= 3) throw "parse"; input.push_back({oppo, user}); } return input; @@ -21,7 +20,7 @@ vector> parse() unsigned p1(vector> &input) { unsigned score = 0; - for (array i : input) { + for (auto i : input) { unsigned shape = i[1]; unsigned outcome = (i[1] - i[0] + 4) % 3; score += shape + 1 + outcome * 3; @@ -32,7 +31,7 @@ unsigned p1(vector> &input) unsigned p2(vector> &input) { unsigned score = 0; - for (array i : input) { + for (auto i : input) { unsigned shape = (i[1] + i[0] + 2) % 3; unsigned outcome = i[1]; score += shape + 1 + outcome * 3;