Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
其实只是多了个无关的判断In Reply To:hawk 我有疑问哈 Posted by:acm1985 at 2006-05-07 15:39:48 > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > > void main() > { > char s1[100000],s2[100000]; > int len1,len2; > int i,j; > while(scanf("%s%s",&s1,&s2)==2) > { > len1=strlen(s1); > len2=strlen(s2); > j=0; > for(i=0;i<len1 && j<len2;i++) > { > while(s1[i]!=s2[j++]) > ; > } > if(i=len1 && j<=len2)//疑问在这里 ,这个程序AC了,但是if语句明显有问题啊,怎么还能AC呢????????????????????????????????????????????? > printf("Yes\n"); > else > printf("No\n"); > } > } 其实只是多了个无关的判断 " if(i=len1 && j<=len2)//疑问在这里 " 把"i=len1"去掉也能过,因为能执行到这一步 len 必然等于 len1 ; 再说"j<=len2",由于"while(s1[i]!=s2[j++])",所以能 YES 的话 j 必然 <= len2 ,否则就是NO 了. 还有一个问题是这"while(s1[i]!=s2[j++])", 我用"person compression"测试,发现 j 循环到了100003 "caseDoesMatter CaseDoesMatter" 测试, j 循环到了100001 显然是没有控制 j 的取值的问题,( 但是它竟然也能停下来 ,就这里有很大问题 ,要不它应该是死循环的 ) ,我是这样写的"for( ; s1[i] != s2[j++] && j <= len2+1 ; )" Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator