-
Notifications
You must be signed in to change notification settings - Fork 814
/
Copy path1112. Stucked Keyboard (20).cpp
45 lines (45 loc) · 1.03 KB
/
1112. Stucked Keyboard (20).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
#include <iostream>
#include <map>
#include <cstdio>
#include <set>
using namespace std;
bool sureNoBroken[256];
int main() {
int k, cnt = 1;
scanf("%d", &k);
string s;
cin >> s;
map<char, bool> m;
set<char> printed;
char pre = '#';
s = s + '#';
for(int i = 0; i < s.length(); i++) {
if(s[i] == pre) {
cnt++;
} else {
if(cnt % k != 0) {
sureNoBroken[pre] = true;
}
cnt = 1;
}
if(i != s.length() - 1) m[s[i]] = (cnt % k == 0);
pre = s[i];
}
for(int i = 0; i < s.length() - 1; i++) {
if(sureNoBroken[s[i]] == true)
m[s[i]] = false;
}
for(int i = 0; i < s.length() - 1; i++) {
if(m[s[i]] && printed.find(s[i]) == printed.end()) {
printf("%c", s[i]);
printed.insert(s[i]);
}
}
printf("\n");
for(int i = 0; i < s.length() - 1; i++) {
printf("%c", s[i]);
if(m[s[i]])
i = i + k - 1;
}
return 0;
}