Ultraviolet A 424-integer inquiry

Source: Internet
Author: User

One of the first users of bit's new supercomputer was Chip Diller. He extended his activation of powers of 3 to go from 0 to 333 and he got Ed taking various sums of those numbers.

''This supercomputer is great, ''remarked chip. ''I only wish Timothy were here to see these results. ''(chip moved to a new apartment, once one became available on the third floor of the lemon sky apartments on Third Street .)

Input

The input will consist of at most 100 lines of text, each of which contains a single verylonginteger. each verylonginteger will be 100 or fewer characters in length, and will only contain digits (no verylonginteger will be negative ).

The final input line will contain in a single zero on a line by itself.

Output

Your program shocould output the sum of the verylongintegers given in the input.

Sample Input

1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900

Sample output

370370367037037036703703703670

I didn't see multiple groups of data wrong. I thought the array was small three times.

# Include <stdio. h>
# Include <string. h>
# Deprecision Max 2000
Int Len, a [Max];
Int change (int A [], char s [])
{Int L = strlen (s), I;
For (I = 1; I <Max; I ++)
A [I] = 0;
For (I = L-1; I> = 0; I --)
A [L-I] = s [I]-'0 ';
Return L;
};
Void sort (char s [])
{Int B [Max], l, I, Lmax;
L = change (B, S );
Lmax = L> Len? L: Len;
For (I = 1; I <= Lmax; I ++)
{A [I] = A [I] + B [I];
A [I + 1] = A [I + 1] + A [I]/10;
A [I] = A [I] % 10;
}
++ Lmax;
While (A [Lmax]> 0)
{A [Lmax + 1] = A [Lmax + 1] + A [Lmax]/10;
A [Lmax] = A [Lmax] % 10;
++ Lmax;
}
While (A [Lmax] = 0) -- Lmax;
Len = Lmax;
};
Void main ()
{Char s [Max], S1 [Max];
Int I;
While (gets (s ))
{
Len = change (A, S );
While (gets (S1 ))
{If (S1 [1] = '\ 0') & (S1 [0] = '0') {for (I = Len; I >= 1; I --) printf ("% d", a [I]); break ;}
Sort (S1 );
}
Printf ("\ n ");
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.