blob: 44d5dc21d997c1f2c7b8eddd31e9cce852f9d376 (
plain)
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
|
#include <fstream>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include <set>
using namespace std;
string
read_file(string_view filename)
{
fstream input{ filename };
return { istreambuf_iterator<char>{ input }, {} };
}
void
solve(const string& data, size_t length)
{
for ( size_t i = 0; i != data.length() - length; ++i ) {
const auto substr = data.substr(i, length);
set<char> set(begin(substr), end(substr));
if (set.size() == length) {
cout << i + length << endl;
break;
}
}
}
int
main()
{
const auto data = read_file("data/day06.txt");
solve(data, 4);
solve(data, 14);
}
|