Poj 1503 Integer Inquiry

1.链接地址:

http://poj.org/problem?id=1503

2.题目:

Integer Inquiry
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 28115   Accepted: 10925

Description

One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored 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 a single zero on a line by itself.

Output

Your program should output the sum of the VeryLongIntegers given in the input.

Sample Input

123456789012345678901234567890

123456789012345678901234567890

123456789012345678901234567890

0

Sample Output

370370367037037036703703703670

Source

3.思路:

4.代码:

 1 #include "stdio.h"

 2 #include "string.h"

 3 #define NUM 102

 4 int a[NUM];

 5 int main()

 6 {

 7     char b[102];

 8     int len;

 9     int max=0;

10     int i;

11     gets(b);

12     while(b[0]-'0'!=0 || strlen(b)!=1)

13     {

14         len = strlen(b);

15         for(i=len-1;i>=0;i--)

16         {

17             a[len-1-i]+=b[i]-'0';

18             if(a[len-1-i]>=10) {a[len-1-i+1]++;a[len-1-i]-=10;}

19         }

20         i=len;

21         while(a[i]>=10){a[i+1]++;a[i]-=10;i++;}

22         gets(b);        

23     }

24     i=NUM-1;

25     while(a[i]==0)i--;

26     while(i>=0)

27     {

28         printf("%c",a[i]+'0');

29         i--;

30     }

31    return 0;

32 }

 

你可能感兴趣的:(Integer)