diff options
author | dzwdz | 2022-12-02 12:39:37 +0100 |
---|---|---|
committer | dzwdz | 2022-12-02 12:39:37 +0100 |
commit | 656d6fb7ee07b70d708b9ec922b7d24cf2989617 (patch) | |
tree | 2f509a7cfb054802fca17d1cf9001be88d61248a /22.2 | |
parent | 9e603f3d65f2a32fdf94a0ed66c7bd408a82f0bb (diff) |
day 2 part 2
Diffstat (limited to '22.2')
-rw-r--r-- | 22.2/main.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/22.2/main.cpp b/22.2/main.cpp index 0ab6017..65e76b6 100644 --- a/22.2/main.cpp +++ b/22.2/main.cpp @@ -2,19 +2,28 @@ using namespace std; int +scoreFor(int their, int mine) +{ + int outcome = (mine - their + 4) % 3; /* 0 loss, 1 draw, 2 win */ + return outcome * 3 + mine + 1; +} + +int main() { char move, res; - long total = 0; + long total1 = 0, total2 = 0; while (scanf("%c %c ", &move, &res) == 2) { move -= 'A'; res -= 'X'; if (!(0 <= move && move < 3)) throw "bad input"; if (!(0 <= res && res < 3)) throw "bad input"; - int outcome = (res - move + 4) % 3; /* 0 loss, 1 draw, 2 win */ - long score = outcome * 3 + res + 1; - total += score; + int mine = (move + res - 1 + 3) % 3; + + total1 += scoreFor(move, res); + total2 += scoreFor(move, mine); } - printf("%ld\n", total); + printf("%ld\n", total1); + printf("%ld\n", total2); } |