Files
advent-of-code/2021/puzzle-08-01.cc
Matthew Gretton-Dann ceb89e10b7 Add 2021 day 8 puzzles
Part two needs a tidy-up which will come in a bit.

But this is how I got the correct answer.
2021-12-08 09:42:51 +00:00

32 lines
690 B
C++

//
// Created by Matthew Gretton-Dann on 08/12/2021.
//
#include <iostream>
#include <string>
auto main() -> int
{
std::string line;
unsigned count{0};
while (std::getline(std::cin, line)) {
line = line.substr(line.find('|') + 1);
unsigned this_digit{0};
for (auto c : line) {
if (c == ' ') {
if (this_digit == 2 || this_digit == 3 || this_digit == 4 || this_digit == 7) {
++count;
}
this_digit = 0;
}
else {
++this_digit;
}
}
if (this_digit == 2 || this_digit == 3 || this_digit == 4 || this_digit == 7) {
++count;
}
}
std::cout << "Simple digits: " << count << '\n';
return 0;
}