UVa 10945

  题目大意:给一个字符串,判断是否回文(忽略大小写,忽略非字母字符)。

 1 #include <cstdio>
 2 #include <cctype>
 3 #include <cstring>
 4 #define MAXN 100000
 5 
 6 char str1[MAXN], str2[MAXN];
 7 
 8 int main()
 9 {
10 #ifdef LOCAL
11     freopen("in", "r", stdin);
12 #endif
13     while (gets(str1))
14     {
15         if (strcmp(str1, "DONE") == 0)  break;
16         int len1 = strlen(str1), len2 = 0;
17         for (int i = 0; i < len1; i++) 
18             if (isalpha(str1[i]))
19                 str2[len2++] = tolower(str1[i]);
20         bool palindrome = true;
21         for (int i = 0, j = len2-1; i < j; i++, j--)
22             if (str2[i] != str2[j])
23             {
24                 palindrome = false;
25                 break;
26             }
27         if (palindrome)  printf("You won't be eaten!
");
28         else  printf("Uh oh..
");
29     }
30     return 0;
31 }
32 
33             
View Code

   今天看《演算法笔记》的时候,无意中看到了Timus,就去刷了一道A+B,美其名曰:熟悉环境,有够无聊的了...^_^

原文地址:https://www.cnblogs.com/xiaobaibuhei/p/3353503.html