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 09101020429 at 2010-09-02 16:10:17 on Problem 1503
#include<stdio.h>
#include<string.h>
int main()
{
	char str[10][50];
	int i,j,a=0,max=0,m,p;
	int len[10],sumstr[51]={0};
	while(1)
	{

		gets(str[a]);
		if(strcmp(str[a],"0")==0)break;
		len[a]=strlen(str[a]);
		if(max<len[a])max=len[a];
		a++;	
	}
	for(i=0;i<a;i++)
	{
		m=max;
		for(j=len[i]-1;j>=0;j--)
		{
			sumstr[m]+=str[i][j]-'0';
			m--;
		}
		for(j=max;j>=0;j--)
		{
			if(sumstr[j]>9)
			{
				sumstr[j-1]=sumstr[j-1]+1;
				sumstr[j]=sumstr[j]-10;
			}
		}
	}
	for(i=0;i<=max;i++)
	{
		if(sumstr[i]!=0)
		{p=i;break;}
	}
	for(i=p;i<=max;i++)
		printf("%d",sumstr[i]);
	printf("\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