Files
contests/advent_of_code/2022/6/main.cpp

45 lines
852 B
C++

#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool check_map_count(const map<T, int>& m, int size){
int result = 0;
for(auto p : m){
if(p.second > 1){
return false;
}
result += p.second;
}
return result == size;
}
int main(){
ifstream input_file("input.txt");
string text;
input_file >> text;
map<char, int> frame;
for(unsigned int i = 0; i < text.length(); ++i){
if(i >= 14){
frame[text[i - 14]]--;
}
frame[text[i]]++;
if(check_map_count(frame, 14)){
for(auto p : frame){
if(p.second > 0){
cout << p.first;
}
} cout << endl;
cout << "Answer: " << i + 1 << endl;
return 0;
}
}
return 0;
}