-
Notifications
You must be signed in to change notification settings - Fork 2
/
06.cpp
48 lines (40 loc) · 1.14 KB
/
06.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
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <chrono>
#include <iostream>
#include <unordered_map>
using std::string;
int main() {
auto tstart = std::chrono::high_resolution_clock::now();
std::unordered_map<char, int> maps[8];
for (unsigned int col = 0; col < 8; col++) {
for (char ch = 'a'; ch <= 'z'; ch++) {
maps[col][ch] = 0;
}
}
string input;
while (std::getline(std::cin, input)) {
for (unsigned int col = 0; col < 8; col++) {
maps[col][input[col]]++;
}
}
string pt1(8, 'a');
string pt2(8, 'a');
for (unsigned int col = 0; col < 8; col++) {
for (char ch = 'b'; ch <= 'z'; ch++) {
if (maps[col][ch] > maps[col][pt1[col]]) {
pt1[col] = ch;
}
if (maps[col][ch] < maps[col][pt2[col]]) {
pt2[col] = ch;
}
}
}
std::cout << "--- Day 6: Signals and Noise ---\n";
std::cout << "Part 1: " << pt1 << "\n";
std::cout << "Part 2: " << pt2 << "\n";
auto tstop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(tstop - tstart);
std::cout << "Time: " << duration.count() << " μs"
<< "\n";
return EXIT_SUCCESS;
}