#include<bits/stdc++.h>
using namespace std;
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)
#define MOD 1000000007
#define MX 100010
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int tc, kk=1, n, vis[1005];
string s;
char ch;
while(cin>>s && s!="end")
{
CLR(vis);
int cnt=0, sl=s.size();
for(int i=0;i<sl;i++)
if(!vis[i])
{
vis[i]=1;
cnt++;
int prev = i;
for(int j=i+1;j<sl;j++)
if(s[prev]>=s[j] && !vis[j])
prev=j, vis[j]=1;
}
cout<< "Case "<<kk++<<": "<<cnt <<"\n";
}
return 0;
}
Can you make me understand the logic?
ReplyDelete