2012-04-04 07:11:39Morris
[UVA] 10945 - Mother bear
Problem C: Mother Bear

Input
You'll be given many sentences. You have to determine if they are palindromes or not, ignoring case and punctuations. Every sentence will only contain the letters A-Z, a-z, '.', ',', '!', '?'. The end of input will be a line containing the word "DONE", which should not be processed.Output
On each input, output "You won't be eaten!" if it is a palindrome, and "Uh oh.." if it is not a palindrome.Sample Input
Madam, Im adam! Roma tibi subito motibus ibit amor. Me so hungry! Si nummi immunis DONE
Sample Output
You won't be eaten! You won't be eaten! Uh oh.. You won't be eaten!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char str[1000];
while(gets(str)) {
if(strcmp(str, "DONE") == 0)
break;
int slen = strlen(str), flag = 0;
int i, j;
for(i = 0, j = slen-1; i < j; i++, j--) {
while(i < slen && isalpha(str[i]) == 0) i++;
while(j >= 0 && isalpha(str[j]) == 0) j--;
if(str[i] >= 'a') str[i] += -'a'+'A';
if(str[j] >= 'a') str[j] += -'a'+'A';
if(i < j && str[i] != str[j]) {
flag = 1;
break;
}
}
if(flag == 0)
puts("You won't be eaten!");
else
puts("Uh oh..");
}
return 0;
}