include<stdio.h>
include<stdlib.h>
define MAXSIZE 7
//定义结构体
struct Stack {
char world[MAXSIZE];
int top;
};
//定义栈
struct temp {
struct Stack s;
};
int main() {
Stack s{};
//入栈
char c1[MAXSIZE] = { 0 };
printf("输入字符串,最多%d个字符\n",MAXSIZE);
for (int i = 0; i < MAXSIZE; i++) {
char c = '0';
scanf_s("%c", &c, sizeof(c));
s.world[++(s.top)] = c;
c1[i] = c;
}
//出栈
printf("字符串输出顺序:\n");
int t = 0;
for (int i = 0; i < MAXSIZE; i++) {
if (s.top>=0) {
printf("%c", s.world[(s.top)]);
printf("\n");
if (s.world[(s.top)] == c1[MAXSIZE-1-i]) {
t++;
}
s.top--;
}
}
if (t == MAXSIZE) {
printf("该串字符是回文!");
}
else {
printf("该串字符不是回文!");
}
return 0;
}