-
Notifications
You must be signed in to change notification settings - Fork 0
/
d6.cpp
70 lines (63 loc) · 1.37 KB
/
d6.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
string filename = argv[1];
ifstream fin;
fin.open(filename.c_str());
if (!fin)
{
cout << "Error opening " << filename << endl;
exit(1);
}
string item;
getline(fin, item);
vector<int> count(26, 0);
int res = 0;
switch (stoi(argv[2]))
{
case 0:
{
int l=0, r=4;
for (size_t i = 0; i < item.length(); i++)
{
if (i>=4)
{
count[item[i-4]-'a'] --;
}
count[item[i]-'a'] ++;
if (count[item[i]-'a'] == 1 && count[item[i-1]-'a'] == 1 && count[item[i-2]-'a'] == 1 && count[item[i-3]-'a'] == 1) {
res = i+1;
break;
}
}
break;
}
case 1:
{
int l = 0, r = 1;
// sliding window, find first window==14
count[item[l]-'a'] ++;
while (r-l < 14)
{
count[item[r]-'a'] ++;
while (count[item[r]-'a'] > 1)
{
count[item[l]-'a'] --;
l ++;
}
r ++;
}
res = r;
break;
}
default:
break;
}
std::cout << res << std::endl;
return 0;
}