/*
============================================================================
Name : 202stack.c
Author : Cly
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include<string.h>
int main(void) {
char a[101],s[101];
int i,len,mid,next,top;
gets(a); //读入一行字符串
len=strlen(a); //求字符串的长度
mid=len/2-1; //求字符串的中点
top=0; //栈的初始化
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--;
}
//如果top值为0,说明栈内所有的字符都被匹配完毕
if(top==0)
printf("YES");
else
printf("NO");
printf("\n%d",s[0]); //堆栈未用到s[0],这里制作测试理解用
}
============================================================================
Name : 202stack.c
Author : Cly
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include<string.h>
int main(void) {
char a[101],s[101];
int i,len,mid,next,top;
gets(a); //读入一行字符串
len=strlen(a); //求字符串的长度
mid=len/2-1; //求字符串的中点
top=0; //栈的初始化
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--;
}
//如果top值为0,说明栈内所有的字符都被匹配完毕
if(top==0)
printf("YES");
else
printf("NO");
printf("\n%d",s[0]); //堆栈未用到s[0],这里制作测试理解用
}