This is an easy problem from uva judge http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1886
Adhoc, palindromes stl.
How I did it
- Read the number of cases.
- Read the string.
- Only save the letters in other string.
- If the string and the rever string are equal print “You won’t be eaten!”. Otherwise print “Uh oh ..”.
Hints
- Really easy using cctype and algorithm libraries.
- Ignore all the characters diferents than letters.
Code
#include <iostream> #include <cstdio> #include <cctype> #include <algorithm> using namespace std; int main() { string str; while(getline(cin,str)) { if(str == "DONE") break; string outR = "", out; for(int x=0; x<str.size(); x++) if(isalpha(str[x])) outR += tolower(str[x]); out = outR; reverse(outR.begin(), outR.end()); if(outR == out) printf("You won't be eaten!\n"); else printf("Uh oh..\n"); } return 0; }