1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <stdio.h> int main(int argc, char *argv[]) { char a[101],s[101]; int i,len,mid,next,top;
gets(a); //读入一行字符串 len = strlen(a); // 求字符串的长度 mid = len/2 - 1; // 求中点 top = 0; //栈初始化 // mid 之前的字符依次入栈
for(i = 0; i <= mid; i++){ s[++top] = a[i]; } if(len % 2 == 0){ next = mid + 1;
}else{ next = mid + 2; }
// 开始匹配
for(i = next;i <= len - 1; i++){ if(a[i] != s[top]) break; top--; }
if(top == 0){ printf("YES"); }else{ printf("NO"); } return 0; }
|