You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
602 B
34 lines
602 B
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
int main() {
|
|
char str[100], stack[100];
|
|
int i, len, mid, next, top;
|
|
|
|
fgets(str, sizeof(str), stdin);
|
|
len = strlen(str);
|
|
mid = len / 2 - 1;//求字符串的中点
|
|
|
|
top = 0;//初始化栈
|
|
for (i = 0; i <= mid; i++) { //将mid前的字符依次压入堆栈
|
|
stack[++top] = str[i];
|
|
}
|
|
|
|
//判断字符串长度是奇数还是偶数,以决定需要匹配的后半部分起始下标
|
|
next = (len % 2) ? (mid+2) : (mid+1);
|
|
|
|
//开始匹配
|
|
for (i = next; i <= len - 1; i++) {
|
|
if (str[i] != stack[top]) break;
|
|
top--;
|
|
}
|
|
|
|
//验证结果
|
|
if (top == 0)
|
|
printf("YES\n");
|
|
else
|
|
printf("No\n");
|
|
|
|
return 0;
|
|
}
|