Description
假设称正读和反读都相同的字符序列为“回文”,例如,‘abba‘ 和 ‘abcba‘是回文,‘abcde‘ 和 ‘ababab‘ 则不是回文。试写一个算法判别读入的一个以‘@‘为结束符的字符序列是否是“回文”。
Input
abcba
Output
是回文
Sample Input
ababab
Sample Output
不是回文
#include <stdio.h>
#include<string.h>
#include <stack>
#include <iostream>
using namespace std;
int main()
{
stack <char> x;
char s[100];
int i;
gets(s);
for(i=0; i<strlen(s); i++)
x.push(s[i]);
for(i=0; i<strlen(s); i++)
if(s[i]==x.top())
x.pop();
if(x.empty())
printf("是回文");
else printf("不是回文");
return 0;
}