You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
37 lines
1.0 KiB
#include <algorithm>
|
|
#include <iterator>
|
|
#include <unordered_set>
|
|
#include <set>
|
|
#include "solutions.hpp"
|
|
|
|
using namespace std;
|
|
|
|
template <>
|
|
pair<string, string> solve<6>(istream& input) {
|
|
uint64_t part1 = 0, part2 = 0;
|
|
unordered_set<char> any_answered;
|
|
unordered_set<char> all_answered;
|
|
bool new_group = true;
|
|
for (string line; getline(input, line); ) {
|
|
if (!line.empty()) {
|
|
unordered_set<char> present;
|
|
for (char c : line) {
|
|
any_answered.insert(c);
|
|
if (new_group || all_answered.contains(c)) {
|
|
present.insert(c);
|
|
}
|
|
}
|
|
all_answered = present;
|
|
new_group = false;
|
|
}
|
|
if (line.empty() || input.peek() == EOF) {
|
|
part1 += any_answered.size();
|
|
part2 += all_answered.size();
|
|
any_answered.clear();
|
|
all_answered.clear();
|
|
new_group = true;
|
|
}
|
|
}
|
|
return pair(to_string(part1), to_string(part2));
|
|
}
|
|
|