#include<iostream>
#include<malloc.h>
using namespace std;
#include<stdlib.h>
#include<string.h>
#define OK 1
#define ERROR 0
#define initsize 100
#define increment 10
typedef char selemtype;
typedef struct
{
selemtype* base;
selemtype* top;
int stacksize;
}Sqstake;
void Initstack(Sqstake& S)
{
S.base = (selemtype*)malloc(initsize * sizeof(selemtype));
if (!S.base)
exit(-1);
S.top = S.base;
S.stacksize = initsize;
}
int Stakempty(Sqstake S)
{
if (S.top == S.base)return OK;
else return ERROR;
}
void Push(Sqstake& S, selemtype e) {
if (S.top - S.base >= S.stacksize) {
selemtype* p = (selemtype*)realloc(S.base, (S.stacksize + increment) * sizeof(selemtype));
if (!p)
exit(-1);
S.top = S.base + S.stacksize;
S.stacksize += increment;
}
*(S.top)++ = e;
}
bool Pop(Sqstake& S, selemtype& e) {
if (S.top == S.base)
return false;
e = *--S.top;
return true;
}
bool Gettop(Sqstake S, selemtype& e) {
if (S.top == S.base)
return false;
e = *(S.top - 1);
return true;
}
void Destory(Sqstake& S) {
free(S.base);
S.base = NULL;
S.top = NULL;
S.stacksize = 0;
}
int Matching(char* exp, int n) {
Sqstake st;
Initstack(st);
char ch;
int i;
for (i = 0; i < n/2; i++)
{
Push(st, exp[i]);
}
i += n % 2;
while (!Stakempty(st))
{
Pop(st,ch);
if (ch != exp[i++])
return 0;
}
return 1;
}
int main() {
char str[100];
cin >> str;
if (Matching(str, strlen(str)))
cout << "1\n";
else
cout << "0\n";
return 1;
}
09-08
2765
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-16
320
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-20
199
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-20
659
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)