24h購物| | PChome| 登入
2012-04-04 07:11:39| 人氣1,449| 回應0 | 上一篇 | 下一篇

[UVA] 10945 - Mother bear

推薦 0 收藏 0 轉貼0 訂閱站台

Problem C: Mother Bear

Unforunately for our lazy "heroes", the nuts were planted by an evil bear known as.. Dave, and they've fallen right into his trap. Dave is not just any bear, he's a talking bear, but he can only understand sentences that are palindromes. While Larry was dazed and confused, Ryan figured this out, but need a way to make sure his sentences are palindromic. So he pulled out his trustly iPod, which thankfully have this program you wrote just for this purpose.. or did you?

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;
}
 

台長: Morris
人氣(1,449) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][DP] 624 - CD
此分類上一篇:[UVA] 10970 - Big Chocolate

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文