zoj1292--------Integer Inquiry 大数
来源:互联网 发布:奥瑞那消防主机编程 编辑:程序博客网 时间:2024/04/30 15:47
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
大数处理,比1205略有不同,这个方法是参考别人的代码并有所修改
代码:
#include<iostream> #include <stdio.h>#include <string.h>using namespace std; void AddS(int A[],char B[],int L){int i,j;i=j=0;for(i=L-1;i>=0;i--,j++){A[j]=A[j]+B[i]-'0';if(A[j]>=10){A[j]=A[j]%10;A[j+1]+=1;}}}int main() {int N,j,i;char B[105];int A[105];cin>>N;while(N--){memset(A,0,sizeof(A)); //memset:作用是在一段内存块中填充某个给定的值memset(B,0,sizeof(B));while(scanf("%s",B)!=EOF&&strcmp(B,"0")!=0)AddS(A,B,strlen(B));for(i=104;!A[i];i--); //这样处理使其从第一个不为零处开始输出 for(j=i;j>=0;j--)cout<<A[j];cout<<endl;if(N)cout<<endl;}return 0; }
- zoj1292--------Integer Inquiry 大数
- ZOJ1292 POJ1503 Integer Inquiry 大数加法
- Integer Inquiry 大数相加
- Integer Inquiry(大数加法)
- HDoj Integer Inquiry(大数)
- Integer Inquiry(大数相加)
- Integer Inquiry 大数相加
- Integer Inquiry(大数)
- 大数加法 424 - Integer Inquiry
- Integer Inquiry(大数加法)
- HDOJ Integer Inquiry (大数累加)
- HDU 1047--Integer Inquiry 【大数】
- HDU 1047 Integer Inquiry【大数】
- HD1047 Integer Inquiry 【大数问题】
- zoj 1292 Integer Inquiry【大数】
- Integer Inquiry 大数加法模板
- HDOJ 1047 Integer Inquiry(大数)
- POJ 1053 Integer Inquiry && HDOJ 1047 Integer Inquiry (大数加法)
- 学习Emacs系列教程(一):基本使用
- 什么样的代码才是好代码???
- 40 个很有用的 Mac OS X Shell 脚本和终端命令
- 嵌入式Linux中基于Qt/Embeded触摸屏驱动的设计
- 英语的重要性
- zoj1292--------Integer Inquiry 大数
- 杂记3
- 一个男人关心的东西决定了他的层次
- 香港金融中心谁与争锋
- poj 3468 线段树 成段更新
- AlarmManager 定时
- 佛感动了
- C++虚继承
- 手机图标收集总结