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 |
一直MLE的同学注意,最后一行没有换行符在递归读取字符时,判断是否要向下延伸时要用 while((c=getchar())=='0') 如果使用 while((c=getchar())!='1'&&c!='\n') 就会MLE,最后一行没有换行符,造成会无限向下递归 使用 while((c=getchar())!=EOF&&c!='\n'&&c!='1') 也可以 这么水的一道题为MLE问题提交了几十次,开始时都用unsigned short还MLE AC代码 # include <stdio.h> # include <string.h> unsigned short in[1501]; char c; unsigned short readstr() { unsigned short n=1; while((c=getchar())=='0') { n+=readstr(); } in[n]++; return n; } unsigned short readstr2() { unsigned short n=1; while((c=getchar())=='0') { n+=readstr2(); } in[n]--; return n; } int main() { int casen,i,j,a,b,c,flag; //freopen("in","r",stdin); scanf("%d\n",&casen); while(casen--) { memset(in,0,sizeof(in)); readstr(); readstr2(); flag=1; for(j=1;j<=800&&flag;j++) if(in[j]!=0) flag=0; if(flag) printf("same\n"); else printf("different\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator