高精度-Integer Inquiry
来源:互联网 发布:cs1.6弹道优化 编辑:程序博客网 时间:2024/05/21 11:31
Integer Inquiry
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 30106 Accepted: 11728
Description
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.)
``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.
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
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900
Sample Output
370370367037037036703703703670
注意此题输入结束标志:输入的那一行有且只有一个0结束,不是输入的第一个字符为0为结束标志,我原先判断结束的标志是当输入的一行字符串中第一个为0时程序结束,为此WA了好几次,在不是结束行中有可能会出现第一个字符为0.故判断结束时不能单单判断第一个字符是否为0,而应进一步说明那一行只有一个字符并接为0;
代码:
#include <iostream>#include <cstdio>using namespace std;int a[1000]={0},b[205]={0};char str[205];int main(){int len1;int j,i;gets(str);int len=strlen(str);for(i=0,j=len-1;j>=0;j--,i++)b[i]=str[j]-'0'; while(1){if(str[0]=='0'&&str[1]=='\0')//注意判断结束的标志break;int h=0;int m; for(j=0;j<len;j++) { m=a[j]+b[j]+h;a[j]=m%10; h=m/10; }while(h){a[j]=h%10;len++;h/=10;}gets(str); len1=strlen(str);for(i=0,j=len1-1;j>=0;j--,i++)b[i]=str[j]-'0'; }int p; for(p=len-1;p>=0;p--)cout<<a[p];cout<<endl;return 0; }
0 0
- Integer Inquiry(高精度)
- 高精度-Integer Inquiry
- poj 1503 Integer Inquiry高精度
- poj 1503 Integer Inquiry【高精度】
- UVa 424 Integer Inquiry (高精度)
- POJ 1503 Integer Inquiry 高精度
- 高精度运算-424 integer inquiry
- POJ1503 Integer Inquiry(高精度加法)
- POJ 1503 Integer Inquiry(高精度运算)
- POJ 1503 Integer Inquiry 高精度加法
- poj 1503Integer Inquiry(高精度 水题)
- POJ 1503 Integer Inquiry 高精度加法
- POJ1503《Integer Inquiry》方法:模拟 高精度
- HDU 1047 Integer Inquiry(高精度加法)
- uva 424 Integer Inquiry(高精度加法)
- UVA 424 Integer Inquiry 高精度加法
- hdu 1047 Integer Inquiry(高精度加法)
- JAVA hdu 1047 Integer Inquiry(高精度)
- 【自考】数据结构导论《逻辑结构AND物理结构》
- Android SwipeRefreshLayout
- 最大子段和
- php Laravel框架学习(二) 之 Eloquent 基础
- JDBC连接MySQL数据库中文乱码
- 高精度-Integer Inquiry
- winsocket学习笔记
- php Laravel框架学习(二) 之 Eloquent 高级应用
- UVA - 101 The Blocks Problem
- hdu2167 方格取数 状态压缩dp
- 剧透——马云为何总拿穷人说事?
- WDK导致开机“dsfksvcs.sys”丢失问题
- Android点赞动画效果 ,点赞后加一,2种方法,①补间动画②位移动画
- MapReduce 编程 系列九 Reducer数目