adventofcode2022/day2/day2part2.cpp
2022-12-02 16:39:08 -07:00

77 lines
2.2 KiB
C++

#include <iostream>
#include <fstream>
#include <string>
int main() {
int score = 0;
int games = 0;
std::ifstream file;
file.open("input");
std::string line;
while (std::getline(file, line)) {
games += 1;
std::cout << games << std::endl;
if (line[0] == 'A') { // Rock
switch(line[2]) {
case 'X':
std::cout << "Loss" << std::endl;
score += 3; // Scissors
break;
case 'Y':
std::cout << "Tie" << std::endl;
score += 3; // Tie
score += 1; // Rock
break;
case 'Z':
std::cout << "Win" << std::endl;
score += 6; // Win
score += 2; // Paper
break;
}
} else if (line[0] == 'B') { // Paper
switch(line[2]) {
case 'X':
std::cout << "Loss" << std::endl;
score += 1; // Rock
break;
case 'Y':
std::cout << "Tie" << std::endl;
score += 3; // Tie
score += 2; // Paper
break;
case 'Z':
std::cout << "Win" << std::endl;
score += 6; // Win
score += 3; // Scissors
break;
}
} else if (line[0] == 'C') { // Scissors
switch(line[2]) {
case 'X':
std::cout << "Loss" << std::endl;
score += 2; // Paper
break;
case 'Y':
std::cout << "Tie" << std::endl;
score += 3; // Tie
score += 3; // Scissors
break;
case 'Z':
std::cout << "Win" << std::endl;
score += 6; // Win
score += 1; // Rock
break;
}
}
//std::cout << line[0] << std::endl;
}
std::cout << score << std::endl;
return 0;
}