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

69 lines
2.1 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[2] == 'X') {
score += 1;
switch(line[0]) {
case 'A':
std::cout << "Tie " << line[0] << " " << line[2] << std::endl;
score += 3;
break;
case 'C':
std::cout << "Win " << line[0] << " " << line[2] << std::endl;
score += 6;
break;
default:
std::cout << "Loss " << line[0] << " " << line[2] << std::endl;
break;
}
} else if (line[2] == 'Y') {
score += 2;
switch(line[0]) {
case 'B':
std::cout << "Tie " << line[0] << " " << line[2] << std::endl;
score += 3;
break;
case 'A':
std::cout << "Win " << line[0] << " " << line[2] << std::endl;
score += 6;
break;
default:
std::cout << "Loss " << line[0] << " " << line[2] << std::endl;
break;
}
} else if (line[2] == 'Z') {
score += 3;
switch(line[0]) {
case 'C':
std::cout << "Tie " << line[0] << " " << line[2] << std::endl;
score += 3;
break;
case 'B':
std::cout << "Win " << line[0] << " " << line[2] << std::endl;
score += 6;
break;
default:
std::cout << "Loss " << line[0] << " " << line[2] << std::endl;
break;
}
}
//std::cout << line[0] << std::endl;
}
std::cout << score << std::endl;
return 0;
}