是否为回文判断,栈的思想

来源:互联网 发布:淘宝联盟数据采集 编辑:程序博客网 时间:2024/06/17 13:59
int main(){int top = 0; int next, i;char a[100], s[100];printf("请输入一串字母或数字:\n");gets(a);int len = strlen(a);int mid = len/2;if(len % 2 == 0){next = mid;} else next = mid+1;//进行入栈for(i = 0; i < mid; i++){s[top] = a[i];top++;} for(i = next; i < len; i++){if(s[top-1] != a[i])break;top--;}if(top == 0){printf("输入的是回文"); }else printf("输入的不是回文"); return 0;} 

0 0