parent
c1df946d1e
commit
dcee17005f
2 changed files with 42 additions and 2 deletions
@ -1,9 +1,46 @@ |
||||
#include "Day02.h" |
||||
|
||||
int Day02::getScore(char opponent, char me) { |
||||
int outcome; |
||||
if (opponent == me) |
||||
outcome = 3; |
||||
else if (opponent == me + 1 || opponent == me - 2) |
||||
outcome = 0; |
||||
else |
||||
outcome = 6; |
||||
return outcome + me - 64; |
||||
} |
||||
|
||||
Result Day02::Task1() { |
||||
return Day::Task1(); |
||||
int score = 0; |
||||
for (string line : input){ |
||||
char predict = line.at(0); |
||||
char answer = char(line.at(2) - 23); |
||||
score += getScore(predict, answer); |
||||
} |
||||
return to_string(score); |
||||
} |
||||
|
||||
Result Day02::Task2() { |
||||
return Day::Task2(); |
||||
int score = 0; |
||||
for (string line : input){ |
||||
char predict = line.at(0); |
||||
char outcome = line.at(2); |
||||
|
||||
char answer; |
||||
if (outcome == 'X'){ |
||||
if (predict > 'A') answer = char(predict - 1); |
||||
else answer = 'C'; |
||||
} |
||||
if (outcome == 'Y'){ |
||||
answer = predict; |
||||
} |
||||
if (outcome == 'Z'){ |
||||
if (predict < 'C') answer = char(predict + 1); |
||||
else answer = 'A'; |
||||
} |
||||
|
||||
score += getScore(predict, answer); |
||||
} |
||||
return to_string(score); |
||||
} |
Loading…
Reference in new issue