Browse Source

Solve problem 6

trunk
Shanti Chellaram 4 years ago
parent
commit
020f3b7c69
  1. 37
      c++/problem6.cpp

37
c++/problem6.cpp

@ -0,0 +1,37 @@
#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));
}
Loading…
Cancel
Save