#include <iostream>
#include <stdlib.h>
#include <string.h>
const int maxsize=20;
using namespace std;
class Stack{
private:
char *s;
int top;
int capacity;
public:
Stack()
{
s=new char[maxsize];
top=0;
}
Stack(int capacity)
{
this->capacity=capacity;
}
~Stack()
{
delete[]s;
}
void push(char e)
{
if(top>maxsize-1)
{
cout<<"overflow!"<<endl;
exit(0);
}
else
s[top++]=e;
}
int pop()
{
return s[--top];
}
bool isEmpty()
{
if(top==0)
return true;
else
return false;
}
};
bool isPalindrome(char *s)
{
Stack mystack;
int index=0;
int len=strlen(s);
for(int i=0;i<len/2;i++)
{
mystack.push(s[index++]);
}
if(len%2==1)
index++;
bool flag=true;
while(!mystack.isEmpty())
{
char ch=mystack.pop();
if(ch!=s[index++])
{
flag=false;
break;
}
}
return flag;
}
int main()
{
char s[maxsize];
cin>>s;
cout<<isPalindrome(s)<<endl;
return 0;
}
C++ 用出入栈判断字符串是否为回文
最新推荐文章于 2024-03-27 19:50:31 发布