Uva 10945 Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i;
    string s;
    map<char, char>a;
    for(i='A';i<='Z';i++)
        a[i] = i;
    for(i='a';i<='z';i++)
        a[i] = i;

    while(getline(cin, s) && s != "DONE")
    {
        string r = "", t = "";
        int c = 0;
        for(i=0;i<s.size();i++)
        {
            char ch = s[i];
            if(a[ch])
            {
                r.push_back(a[ch]);
                c++;
            }
        }
        if(c%2 == 1)
        {
            int p = c/2;
            for(i=0;i<r.size();i++)
            {
                if(i == p)
                    continue;
                else
                    t.push_back(r[i]);
            }
            r = t;
        }
        transform(r.begin(), r.end(), r.begin(), ::tolower);
        string g = r;
        reverse(g.begin(), g.end());
        if(g == r)
            cout << "You won't be eaten!" << endl;
        else
            cout << "Uh oh.." << endl;
    }
    return 0;
}

Comments