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

为什么这样就要快那么多呢?搞不懂!

Posted by hubo430 at 2006-03-29 11:02:51 on Problem 2190
#include<stdio.h>
#include<string.h>
本来是这样的程序,用了15毫秒
int main()
{
	int sum=0,time,i,t,top;
	char s[11];
	scanf("%s",s);
	for(i=0;i<=9;i++)
	{
		if(s[i]>='0'&&s[i]<='9') sum+=(s[i]-'0')*(10-i);
		else if(s[i]=='X') sum+=10*(10-i);
		else {time=10-i;t=i;}
	}
	if(t==9) top=10;else top=9;
	t=-1;
	for(i=0;i<=top;i++)
		if((sum+i*time)%11==0) {t=i;break;}
	if(t==10) printf("X\n");
	else printf("%d\n",t);
	return 0;
}
换成这样后就没用什么时间了
#include<stdio.h>
#include<string.h>
int main()
{
	int sum,time,i,t,top;
	char s[11];
	while(scanf("%s",s)==1)
	{
		sum=0;
		for(i=0;i<=9;i++)
		{
			if(s[i]>='0'&&s[i]<='9') sum+=(s[i]-'0')*(10-i);
			else if(s[i]=='X') sum+=10*(10-i);
			else {time=10-i;t=i;}
		}
		if(t==9) top=10;else top=9;
		t=-1;
		for(i=0;i<=top;i++)
			if((sum+i*time)%11==0) {t=i;break;}
		if(t==10) printf("X\n");
		else printf("%d\n",t);
	}
	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