Sunday 16 August 2015

UVALive 3755 Being Smarty!

#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

string reverse (string s)
{
    string result="";
    int sl=s.length();
    for (int i=0; i<sl; i++)
        result = s[i] + result ;
return result;
}

int main()
{
    int tc,kk=1, n, r, sl;
    string s;

    while(cin>>r && r)
    {
        cin>>n;
        getline(cin,s);
        sl=s.length();
        int pos=0;
        while(s[pos]==' ') pos++;
        
        string s1="";
        string s2="";
        if(s[pos]=='"')
        {
            pos++;
            while(s[pos]!='"')
            {
                s1+=s[pos];
                pos++;
            }
        }
        else
        {
            while(s[pos]!=' ')
            {
                s1+=s[pos];
                pos++;
            }
        }
        pos=sl-1;
        while(s[pos]==' ') pos--;
        if(s[pos]=='"')
        {
            pos--;
            while(s[pos]!='"')
            {
                s2+=s[pos];
                pos--;
            }
        }
        else
        {
            while(s[pos]!=' ')
            {
                s2+=s[pos];
                pos--;
            }
        }
        s2=reverse(s2);
      
        for(int i=0;i<s1.length();i++)
            if(s1[i]>='A' && s1[i]<='Z')
                s1[i]=tolower(s1[i]);
        for(int i=0;i<s2.length();i++)
            if(s2[i]>='A' && s2[i]<='Z')
                s2[i]=tolower(s2[i]);
        cout<<kk++<<". ";
        if(((r-1)/n)%2==0)
            cout<<s1<<endl;
        else cout<<s2<<endl;

    }
    return 0;
}

No comments:

Post a Comment