Wednesday, 9 September 2015

UVA 1062 Containers (UVALive 3752, World Finals >> 2007 - Tokyo)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

#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;
}

1 comment: