#include <stdio.h> #include <stdlib.h> #define MAXSIZE 100 //元素进栈 int push(char* zhan,int top,char elem){ zhan[top]=elem; top++; return top; } //元素出栈 int pop(char * zhan,int top){ if (top==-1) { printf("空栈"); return -1; } top--; return top; } int main() { int num; scanf("%d",&num); char a[MAXSIZE]; char zhan[MAXSIZE]; int top=-1; getchar(); gets(a); for(int k=0;k<num;k++) { if(a[k]==' ') { printf("入栈不成功"); exit(0); } top=push(zhan,top,a[k]); } int count=0; for(int j=0;j<num;j++) { top=pop(zhan,top); if(a[j]!=zhan[top]) { count++; } } if(count==0) { printf("此字符串是回文串"); } else { printf("此字符串不是回文串"); } return 0; }
标签:return,int,top,char,MAXSIZE,zhan,回文 From: https://www.cnblogs.com/kk4458/p/16785756.html