ZOJ 1292 Integer Inquiry
来源:互联网 发布:网络服务器是什么 编辑:程序博客网 时间:2024/05/01 01:50
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 MAX 200
int main()
{
int sum[MAX];
int N,i;
char str[MAX];
scanf("%d",&N);
getchar();
while(N--){
memset(sum,0, sizeof(sum));
while (scanf("%s",str)&&strcmp(str,"0")) {
int len=strlen(str);
for(i=len-1;i>=0;i--)
sum[len-i-1]+=str[i]-'0';
}
int flag=0;
for(i=0;i<MAX;i++)//大数相加一般都这么做
{
int temp=flag+sum[i];
flag=temp/10;
sum[i]=temp%10;
}
i=MAX-1;
while(sum[i]==0)
i--;
if(i<0) printf("0");
else {
for(;i>=0;i--)
printf("%d",sum[i]);
}
printf("\n");
if(N!=0)
printf("\n");
}
return 0;
}
- ZOJ 1292 Integer Inquiry
- ZOJ 1292 Integer Inquiry
- zoj 1292 Integer Inquiry
- ZOJ 1292 Integer Inquiry
- ZOJ 1292 Integer Inquiry
- zoj 1292 Integer Inquiry
- zoj 1292 Integer Inquiry【大数】
- zoj 1292 Integer Inquiry(大数)
- ZOJ 1292/HDU 1047 Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- 在MAC下配置mysql数据库的编码问题
- 通过pdf实现seo
- ESX 3.5安装说明
- 大型网站架构演变和知识体系
- error C2660: 'CWnd::HtmlHelpW ' : function does not take 4 arguments
- ZOJ 1292 Integer Inquiry
- 7.Struts采用EL保持表单数据:改成用struts的html标签保持数据
- 说说企业架构(企业级架构)和应用程序架构
- VC++学习笔记2--如何给MFC对话框添加背景图片
- 与冯大辉谈数据库架构(InfoQ)
- 关于如何从PSD转换为HTML&CSS的教程
- Oracle游标(二)隐式游标
- 如何快速的增加行业经验
- 1.Struts设置ActionForm为session 界面