c语言 回文判断

[复制链接]
查看11 | 回复2 | 2009-3-23 23:39:26 | 显示全部楼层 |阅读模式
试编写一个算法,判断依次读入的一个以@为结束符的字母列,是否为形如‘序列1&序列2’模式的字符序列。其中序列1和序列2中都不含字符‘&’,且序列2是序列1的逆序列。例如,‘a+b&b+a’是属于该模式的字符序列,而‘1+3&3-1’则不是。
要用栈和队列

回复

使用道具 举报

千问 | 2009-3-23 23:39:26 | 显示全部楼层
下面的程序在Turbo C 2.0下调试通过,结果正确,没有问题:#include int check(char s[]){int i=0,j;while (s && s!='@') i++;if (s!='@') return 0;j=i/2;if (s[j]!='&') return 0;i=j-1;j++;while(i>=0){if (s!=s[j]) return 0;i--;j++;}return 1;}main(){char s[255];gets(s);printf("%s\n",check(s)?"YES"...
回复

使用道具 举报

千问 | 2009-3-23 23:39:26 | 显示全部楼层
我的简单,用我的。#include int main(){ char str[80]; int i, j = 0; scanf("%s", str); while (str[j++] != '&'); i = j - 2; while (i>0) {if (str[i--] !...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则