Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一直MLE的同学注意,最后一行没有换行符

Posted by iscubus at 2011-10-19 13:15:15 on Problem 1635
在递归读取字符时,判断是否要向下延伸时要用
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator