-
Notifications
You must be signed in to change notification settings - Fork 0
/
stuckedKeyboard.cpp
78 lines (72 loc) · 1.47 KB
/
stuckedKeyboard.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
71
72
73
74
75
76
77
78
#include<iostream>
#include<stdio.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;
unordered_map<char, int> smap;
set<char> cset;
void stateChange(char v, int state){
// 0 init 1 stuck 2 not
if(state == 2){
smap[v]=2;
}
else
{
if(smap.find(v)==smap.end()){
smap[v]=1;
}
else
{
if(smap[v]==2){
return;
}
else
{
smap[v]=1;
}
}
}
}
int main(){
int stn;
cin>>stn;
string txt;
cin>>txt;
int l=txt.length();
for(int i=0;i<txt.length()-stn+1;i++){
int tmps = 1;
for(int j=1;j<stn;j++){
if(txt.at(i)!=txt.at(i+j)){
tmps=2;
break;
}
}
if(tmps==2){
stateChange(txt.at(i), 2);
}
else
{
stateChange(txt.at(i), 1);
i+=stn-1;
}
}
for(int i=0;i<txt.length();i++){
if(smap.find(txt.at(i))!=smap.end() && smap[txt.at(i)]==1 && cset.find(txt.at(i))==cset.end()){
cout<<txt.at(i);
cset.insert(txt.at(i));
}
}
cout<<endl;
for(int i=0;i<txt.length();i++){
if(smap.find(txt.at(i))!=smap.end() && smap[txt.at(i)]==1){
cout<<txt.at(i);
i+=stn-1;
}
else
{
cout<<txt.at(i);
}
}
cout<<endl;
}