【菜鸟求助】ACM题目:Integer Inquiry

来源:百度知道 编辑:UC知道 时间:2024/05/27 11:40:06
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
12

你的代码在判断最高位上有问题
比如
9
90
999
0

你的代码输出98
正确答案应该是1098

不好意思,我的代码是直接贴的下面这题AC的代码
http://acm.hdu.edu.cn/showproblem.php?pid=1047
这题一开始输入了例子个数
杠掉前三行就行了
我现在身边没有编译器,不过我估计你改了后无法避免输出前面的无效零
比如
0009
9
9
你会输出多余的0

这是我的代码

#include<stdio.h>
#include<string.h>
char s[200];
int t[200];
int n,l,i,j,ll;
bool first=1;
int main()
{
//scanf("%d",&n);
// while (n--)
{
// if (first) first=0; else

memset(t,0,sizeof t);
ll=1;
while (scanf("%s",s)==1)
{
l=strlen(s);
if (l==1&&s[0]==48) break;
for (i=l-1,j=0;i>=0;i--,j++)
{
t[j]+=s[i]-48;