zoj 1292
来源:互联网 发布:大数据 nosql 论文 编辑:程序博客网 时间:2024/05/01 04:58
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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Sample Input
123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
Sample Output
370370367037037036703703703670
代码:
#include <stdio.h>
#include <string.h>
#define LENG 105
void addsum(int *strsum,char *str,int length);
int main()
{
int n,j,i;
char str[LENG];
int strsum[LENG];
scanf("%d",&n);
while(n--)
{
memset(strsum,0,sizeof(strsum));
memset(str,0,sizeof(str));
while(scanf("%s",str)!=EOF&&strcmp(str,"0")!=0)
{
addsum(strsum,str,strlen(str));
}
for(i=LENG-1;!strsum[i];i--);
for(j=i;j>=0;j--)
{
printf("%d",strsum[j]);
}
printf("\n");
if (n)
{
printf("\n");
}
}
return 0;
}
void addsum(int *strsum,char *str,int length)
{
int i,j=0;
for(i=length-1;i>=0;i--,j++)
{
strsum[j]+=str[i]-'0';
if (strsum[j]>=10)
{
strsum[j]=strsum[j]%10;
strsum[j+1]+=1;
}
}
}
- zoj 1292
- zoj 1292
- ZOJ-1292
- ZOJ 1292 Integer Inquiry
- ZOJ 1292 Integer Inquiry
- zoj 1292 Integer Inquiry
- ZOJ 1292 大数相加
- ZOJ 1292 Integer Inquiry
- ZOJ 1292 Integer Inquiry
- zoj 1292 Integer Inquiry
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- WPF 关于C#代码实现ControlTemplate
- 字节流
- 左select, 右带checkbox的虚拟select互相移动
- Andorid学习笔记(草稿)
- ubuntu10.04 wine安装source insight3.5
- zoj 1292
- 影响apache性能的几个重要参数
- Cairngorm教会你什么?
- 安装 VS2008 HRESULT -2147023293 失败解决方法
- GCC中switch的扩展
- VMware虚拟机修改硬盘大小的方法
- poj 2060(最小路径覆盖)
- DB2 alter table 的字段后,不能添加新数据,报错SQL0668N Operation not allowed for reason code "7" on table
- SQL技巧集锦