Integer Inquiry
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 33777 | Accepted: 13157 |
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.)
``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.
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
#include
#define MAXN 105
int b[MAXN];
char a[MAXN];
int main(){
int len,i,j,k;
while(scanf("%s",a)!=EOF){
if(strcmp(a,"0")==0){
break;
}
else{
len=strlen(a);
for(i=0;i
=10){
b[j+1]=b[j+1]+b[j]/10;
b[j]=b[j]%10;
}
}
}
}
k=MAXN;
while(b[--k]==0);
while(k>=0){
printf("%d",b[k--]);
}
}
本文介绍了一个关于VeryLongInteger求和的问题,通过读取一系列不超过100个字符的非负整数,并输出这些整数的总和。使用C语言实现,主要涉及字符串处理和大数运算。
1191

被折叠的 条评论
为什么被折叠?



