POJ 1503 大整数相加的问题

来源:互联网 发布:网络运行情况通报 编辑:程序博客网 时间:2024/05/22 15:24
开数组时,要开一个大数组,不然不通过。题意不明确,尼玛死,害老子在图书馆坐了一整天。。。



Integer Inquiry
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 26461 Accepted: 10258

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

1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900

Sample Output

370370367037037036703703703670

Source

East Central North America 1996



#include<stdio.h>#include<string.h>int main(){char a[1000],b[1000],c[1010],d[1010];int m,n,r,i=0,p=0,s=0,count=1;gets(a);    gets(b);for(;i<1010;i++)d[i]='0';n=strlen(b);for(i=n-1;i>=0;i--){d[p]=b[i];p++;   }while(count<100){if(count!=1)gets(a);if(!strcmp(a,"0"))break;for(i=0;i<1010;i++)c[i]='0';m=strlen(a);p=0;for(i=m-1;i>=0;i--){c[p]=a[i];p++;}for(i=0;i<1010;i++){r=c[i]+d[i]+s-96;s=r/10;            d[i]=r%10+48;}count++;}    for(i=1009;d[i]=='0';i--);for(;i>=0;i--)printf("%d",d[i]-'0');printf("\n");return 0;}