| ||||||||||
| 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 | |||||||||
Re:WhyIn 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator