回文字符串

题目截图:

 

思路:

  遍历字符串前半部分,判断对称部分是否相等即可。

代码如下:

 1 /*
 2     回文字符串 
 3 */
 4 
 5 #include <stdio.h>
 6 #include <string.h>
 7 #include <math.h>
 8 #include <stdlib.h>
 9 #include <time.h>
10 #include <stdbool.h>
11 
12 char str[1001]; 
13 
14 int main() {
15     while(scanf("%s", str) != EOF) {
16         int len = strlen(str);        // 字符串长度 
17         int i;
18         for(i=0; i<len/2; ++i) {    // 遍历前半部分 
19             if(str[i] != str[len-1-i]) {
20                 break;                // 不相等,则不为回文 
21             } 
22         }
23         if(i < len/2) {                // 输出 
24             printf("No!
");
25         } else {
26             printf("Yes!
");
27         }
28     }
29 
30     return 0;
31 }
原文地址:https://www.cnblogs.com/coderJiebao/p/HustTest24.html