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

Re:Why

Posted by luxuejuncarl at 2007-06-06 02:00:17 on Problem 1503
In Reply To:Why Posted by:luxuejuncarl at 2007-06-06 01:59:48
WA:
#include<stdio.h>
#include<string.h>
#define MAX 103
char a[MAX][MAX];
char s[MAX];
int main()
{
	int i, j, num, maxLen, carry;
	for(i=0; scanf("%s", s) && !(s[0]=='0' && s[1]==0); i++)
	{
		a[i][0] = strlen(s);
		for(j=1; j<=a[i][0]; j++)
			a[i][j] = s[a[i][0]-j] - '0';
	}
	num = i;
	for(i=1; i<num; i++)
	{
		carry = 0;
		maxLen = a[0][0];
		if(a[i][0] > maxLen)
			maxLen = a[i][0];
		for(j=1; j<=maxLen; j++)
		{
			a[0][j] += carry + a[i][j];
			carry = a[0][j] / 10;
			a[0][j] %= 10;
		}
		if(carry != 0)
			a[0][maxLen+1] = carry;
	}
	
	i = MAX-1;
	while(a[0][i] == 0)
		i--;
	for(; i>=1; i--)
		printf("%d", a[0][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