Sunday, 16 August 2015

UVA 12582 Wedding of Sultan (UVALive 6201, Regionals 2012 >> Asia - Dhaka)

#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()
{
    int sl, tc,kk=1, n, arr[30];
    string s;
    cin>>tc; 
    while(tc--)
    {
        CLR(arr);
        cin>>s;
        sl=s.length();
        stack<char>st;
        st.push(s[0]);
        st.push(s[1]);
        for(int i=2;i<sl-1;i++)
        {
            char tmp=st.top();
            if(st.top()==s[i])
            {
                arr[s[i]-'A']++;
                st.pop();
                arr[st.top()-'A']++;
            }
            else st.push(s[i]);
        }
        cout<<"Case "<<kk++<<endl;
        for(int i=0;i<26;i++)
            if(arr[i])
                cout<<char(i+'A')<<" = "<<arr[i]<<endl;
    }
    return 0;
}

No comments:

Post a Comment