-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBROKEN.c
72 lines (69 loc) · 1.26 KB
/
BROKEN.c
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
#include<bits/stdc++.h>
using namespace std;
set<char> st;
multiset<char> mst;
string str;
void prints(set<char> st)
{
set<char>::iterator is;
for(is=st.begin();is!=st.end();++is)
{
cout<<*is;
}
cout<<" "<<st.size()<<endl;
}
void printm(multiset<char> mst)
{
multiset<char>::iterator is;
for(is=mst.begin();is!=mst.end();++is)
{
cout<<*is;
}
cout<<" "<<mst.size()<<endl;
}
int main()
{
int m;
scanf("%d",&m);
//cout<<m<<" ";
while(m)
{
getline(cin,str);
getline(cin,str);
string::iterator ib,ie;
//for(ib=str.begin();ib!=str.end();++ib)
//{
// if(*ib==' ') *ib='&';
//}
//cout<<"i got string=";
//cout<<str<<endl;
ib=ie=str.begin();
int maxs=0;
multiset<char>::iterator im;
while(ie!=str.end())
{
st.insert(*ie);
mst.insert(*ie);
//prints(st);
//printm(mst);
if(st.size()>m)
{
while(st.size()!=m && ib!=ie)
{
im=mst.find(*ib);
mst.erase(im);
if(mst.find(*ib)==mst.end()) st.erase(*ib);
++ib;
}
}
if(mst.size() > maxs) maxs = mst.size();
ie++;
//prints(st);
//printm(mst);
}
cout<<maxs<<endl;
scanf("%d",&m);
st.clear();
mst.clear();
}
}