今天进行了回文串的练习,上午进行了金属创意制作,充分发挥了自己的 动手能力。下午进行了建民老师的课,对类和对象进行了加深学习。课上代码还未完成。。。。。。。
#include<stdio.h> #include<stdlib.h> #include<string.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(); fgets(a,MAXSIZE,stdin); a[strcspn(a,"\n")]=0; for(int i =0;i<num;i++){ if(a[i]==' ') { printf("入栈不成功"); exit(0); } top= push(zhan,top,a[i]); } 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; }
标签:2023.09,return,25,int,top,char,MAXSIZE,zhan From: https://www.cnblogs.com/dmx-03/p/17730941.html