-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_06b.cpp
35 lines (32 loc) · 1.04 KB
/
day_06b.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <algorithm>
#include <cctype>
#include <fstream>
#include <iostream>
#include <unordered_set>
int main() {
std::ifstream file;
file.open("../input/day_06_input");
const std::string full_string = "abcdefghijklmnopqrstuvwxyz";
int count = 0;
std::string line;
std::string intersection = full_string;
while (std::getline(file, line)) {
line.erase(std::remove_if(std::begin(line), std::end(line),
[](auto c) { return !isprint(c); }),
std::end(line));
if (line.empty()) {
count += intersection.size();
intersection = full_string;
} else {
std::sort(std::begin(line), std::end(line));
std::string temp_intersection = "";
std::set_intersection(std::begin(line), std::end(line),
std::begin(intersection), std::end(intersection),
std::back_inserter(temp_intersection));
intersection = temp_intersection;
}
}
count += intersection.size();
std::cout << count << '\n';
return count;
}