Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <map>
- #include <string>
- int main() {
- int twos = 0;
- int threes = 0;
- std::string line;
- std::ifstream inFile;
- inFile.open("aoc-input-2");
- while (inFile >> line) {
- std::map<char, int> counts;
- for(char& c : line) {
- if(counts.count(c) == 0) {
- counts[c] = 1;
- } else {
- ++counts[c];
- }
- }
- bool foundTwos = false;
- bool foundThrees = false;
- auto it = counts.begin();
- while(it != counts.end()) {
- if (!foundTwos && it->second == 2) {
- ++twos;
- foundTwos = true;
- if (foundThrees) break;
- } else if (!foundThrees && it->second == 3) {
- ++threes;
- foundThrees = true;
- if (foundTwos) break;
- }
- ++it;
- }
- }
- inFile.close();
- std::cout << (twos * threes) << std::endl;
- }
Add Comment
Please, Sign In to add comment