/*
回文
算法:比较
数据结构:栈
*/
#include<bits/stdc++.h>
using namespace std;const int maxn=1000;
bool palindrome(char *str)
{
int i;
int len=strlen(str);
stack<char>S;//前一半入栈
for(i=0; i<len/2; i++)
S.push(str[i]);
//奇数跳过中心点
if(len%2==1)
i++;
//判断比较
while(!S.empty())
{
if(str[i]!=S.top())
return false;
else
{
i++;
S.pop();
}
}
return true;
}
int main()
{
char str[maxn];
while(cin>>str)
{
if(palindrome(str))
cout<<"yes palindrome"<<endl;
else
cout<<"no palindrome"<<endl;
}
return 0;
}
01-25
1175
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)