424 - Integer Inquiry
来源:互联网 发布:python输入ctrl c 编辑:程序博客网 时间:2024/06/07 00:43
One of the first users of BIT's new supercomputer was ChipDiller. He extended his exploration of powers of 3 to go from 0 to333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wishTimothy were here to see these results.'' (Chip moved to a newapartment, once one became available on the third floor of theLemon Sky apartments on Third Street.)
Input
The input will consist of at most 100 lines of text, each ofwhich contains a single VeryLongInteger. Each VeryLongInteger willbe 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 byitself.
Output
Your program should output the sum of the VeryLongIntegers givenin the input.
SampleInput
123456789012345678901234567890123456789012345678901234 567890123456789012345678901234 5678900
SampleOutput
370370367037037036703703703670
代码:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
int i,j,len,max,line,flen[101],c,sum;
char text[102][101],text1[102][101],ans[103];
while(1)
{
line=max=0;
while(scanf("%s",text[line])==1)
{
len=strlen(text[line]);
if(len==1 && text[line][0]=='0')break;
else
{
for(i=0,j=len-1;i<len;i++,j--)
text1[line][j]=text[line][i];
flen[line]=len;
if(len>max)max=len;
line++;
}
}
for(i=0;i<line;i++)
{
for(j=flen[i];j<max-1;j++)
text1[i][j]='0';
text1[i][j]='\0';
}
c=0;
for(i=0;i<max;i++)
{
sum=0;
for(j=0;j<line;j++)
sum=sum+(text1[j][i]-'0');
sum=sum+c;
ans[i]=(sum)+'0';
c=sum/10;
}
if(c!=0)
{
if(c>10)
{
ans[i++]=(c)+'0';
ans[i]=(c/10)+'0';
}
else
ans[i]=c+'0';
for(j=i;j>=0;j--)
printf("%c",ans[j]);
}
else
{
for(j=i-1;j>=0;j--)
printf("%c",ans[j]);
}
printf("\n");
break;
}
return 0;
}
- 424 - Integer Inquiry
- POJ 1503 Integer Inquiry(大数加…
- leetcode:Integer to Roman + Fin…
-  
-
- A + B Problem (Big integer versi…
- A * B Problem (Big integer versi…
- poj 1716 Integer Intervals(差分…
- hdoj acm 1008
- HDOJ 1984 Mispelling4
- em的错误 <转载>
- 集线器 交换机 路由器 网桥 …
- 死亡日志 ——黄妮超
- 使用BBED修改SCN …
- IOS 99乘法表
- 考 研 问 答
- hdoj acm 1029
- Rightmost Digit hdoj 1061
- uva 10010 - Where's Waldorf?
- uva 10361 - Automatic Poetry
- uva 401 - Palindromes
- uva UVa 537 Artificial Intellige…
- 409 Excuses, Excuses!
- 424 - Integer Inquiry
- 10106 - Product
- 465 - Overflow
- 安卓:内容提供者(基础知识)
- Problem A
- Problem B
- Problem F
- Problem G
- Problem C