-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1371.cpp
More file actions
39 lines (30 loc) · 821 Bytes
/
1371.cpp
File metadata and controls
39 lines (30 loc) · 821 Bytes
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
#include<iostream>
#include<vector>
#include<bitset>
int findTheLongestSubstring(std::string s) {
std::vector<int> first(32, -2);
first[0] = -1;
int state = 00000;
int max = 0;
for (int i = 0; i < s.size(); ++i) {
switch (s[i]) {
case 'a': state ^= (1 << 0); break;
case 'e': state ^= (1 << 1); break;
case 'i': state ^= (1 << 2); break;
case 'o': state ^= (1 << 3); break;
case 'u': state ^= (1 << 4); break;
}
if (first[state] == -2) {
first[state] = i;
}
if (max <= i - first[state]) {
max = i - first[state];
}
}
return max;
}
int main() {
std::string s = "eleetminicoworoep";
std::cout << findTheLongestSubstring(s);
std::cin.get();
}