[解题报告]424 Integer Inquiry

 Integer Inquiry 

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



现在大数题基本上习惯用字符组处理了
#include<stdio.h>
#include<string.h>
char p[1000];
int o[1001];
int main()
{
 int a,b,c,i;
 while(scanf("%s",p)!=EOF)//输入加数,以字符组形式存储
 {
  if(p[0]=='0')break;
  b=strlen(p);
  for(a=b-1,i=0;a>=0;a--,i++)
   o[i]+=p[a]-'0';//将输入的加数倒序存储为数组,加数每位占一个单位。由于输入是从左到右,而运算是从右到左,这样处理符合从右到左的运算习惯
 }
 for(b=0;b<=150;b++)
 {
  if(o[b]>=10)//如果输入的数大于是10,则保留个位,向后一位加上自己的十位数部分,也就是进位
  {
   o[b+1]+=o[b]/10;
   o[b]=o[b]%10;
  }
 }
 c=0;
 for(b=150;b>=0;b--)//输出还是要从左到右输出,所以倒序输出
 {
  if(o[b]!= 0)//只输出非零部分
   c=1;
  if(c)
   printf("%d",o[b]);
 }
if(c==0)//这是针对输入为0的情况。也就是第10行语句退出循环后执行的部分
printf("0");
 printf("\n");
 return 0;
}
原文地址:https://www.cnblogs.com/TheLaughingMan/p/2924685.html