#include #include using namespace std; // A:X Rock | 1 // B:Y Paper | 2 // C:Z Scissors | 3 // Loss: 0 | Draw: 3 | Win: 6 // X: Loose | Y: Draw | Z: Win class Play { public: int value; int beats; char looses; Play(){}; Play(char playType) { if (playType == 'A' || playType == 'X') { value = 1; beats = 3; looses = 'B'; } else if (playType == 'B' || playType == 'Y') { value = 2; beats = 1; looses = 'C'; } else { value = 3; beats = 2; looses = 'A'; } } int compete(Play* other) { int score {this->value}; if (this->beats == other->value) return score + 6; else if (score == other->value) return score + 3; else return score; } }; char toPlayType(int value) { switch (value) { case 1: return 'A'; case 2: return 'B'; case 3: return 'C'; } } int main() { ifstream inputFile("input.txt"); string game; int totalScore {0}; while (getline(inputFile, game)) { // Split this text of the game cout << '\n' << game[2] << " " << game[0] << endl; Play them {Play(game[0])}; Play me; switch (game[2]) { case 'X': me = Play(toPlayType(them.beats)); break; case 'Y': me = Play(toPlayType(them.value)); break; case 'Z': me = Play(them.looses); break; } int score = me.compete(&them); cout << me.value << " vs " << them.value << "\t| " << score << endl; totalScore += score; } cout << '\n' << totalScore << endl; }