Problem Description

Oneof the first users of BIT's new supercomputer was Chip Diller. He extended hisexploration of powers of 3 to go from 0 to 333 and he explored taking varioussums of those numbers. 

``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were hereto see these results.'' (Chip moved to a new apartment, once one becameavailable on the third floor of the Lemon Sky apartments on Third Street.)

Input

Theinput will consist of at most 100 lines of text, each of which contains asingle VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters inlength, 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

Yourprogram 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 followedby N input blocks. Each input block is in the format indicated in the problemdescription. There is a blank line between input blocks.



The output format consists of N output blocks. There is a blank line betweenoutput blocks.

Sample Input

1

123456789012345678901234567890

123456789012345678901234567890

123456789012345678901234567890

0

Sample Output

370370367037037036703703703670

Source

East Central North America 1996

参照前辈的, 用string写的一个高精度加法模板:

Code:

#include<iostream>
#include<string>
using namespace std;
string add(string x,string y)
{
string ans ;
int lenx = x.length();
int leny = y.length();
if(lenx<leny)
{
for(int i = 1;i<=leny-lenx;i++)
x = "0"+x;
}
else
{
for(int i = 1;i<=lenx-leny;i++)
y = "0"+y;
}
lenx = x.length();
int cf = 0;
int temp;
for(int i = lenx-1;i>=0;i--)
{
temp = x[i] - '0' + y[i] - '0'+cf;
cf = temp/10;
temp%=10;
ans = char('0'+temp)+ans;
}
if(cf!=0)
ans = char(cf+'0')+ans;
return ans;
} int main()
{
int t;
string x,sum;
cin>>t;
while(t--)
{
sum = "0";
while(cin>>x&&x!="0")
{
sum = add(sum,x);
}
cout<<sum<<endl;
if(t>0)
cout<<endl;
}
}

hdu 1047 Integer Inquiry(高精度数)的更多相关文章

  1. hdu 1047 Integer Inquiry

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...

  2. HDU 1047 Integer Inquiry( 高精度加法水 )

    链接:传送门 思路:高精度水题 /************************************************************************* > File ...

  3. HDU 1047 Integer Inquiry 大数相加 string解法

    本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...

  4. hdu 1047 Integer Inquiry(大数)

    题意:整数大数加法 思路:大数模板 #include<iostream> #include<stdio.h> #include<stdlib.h> #include ...

  5. hdu acm-1047 Integer Inquiry(大数相加)

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. hdoj 1047 Integer Inquiry

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. poj 1503 Integer Inquiry (高精度运算)

    题目链接:http://poj.org/problem?id=1503 思路分析: 基本的高精度问题,使用字符数组存储然后处理即可. 代码如下: #include <iostream> # ...

  8. 1047 Integer Inquiry

    String 大数加法模板 #include<stdio.h> #include<string> #include<iostream> using namespac ...

  9. hdu 4651 Partition && hdu 4658 Integer Partition——拆分数与五边形定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651 参考:https://blog.csdn.net/u013007900/article/detail ...

随机推荐

  1. ecshop中index.dwt文件分析

    对于ecshop新手来说,这篇总结值得关注. 对于没有web编程基础的同学来说,ecshop模板里面有两个文件特别重要, 但是这两个文件同时也很不好理解,分别是index.dwt和style.css. ...

  2. Tomcat无法部署项目

    设置项目的Jdk,compire version 增加java EE 如果有必要,现在项目根目录下放置.mymetadata文件 <?xml version="1.0" en ...

  3. 放弃移动版Flash而非AIR

    之前看到标题为"Adobe放弃移动版flash"的新闻,我很震惊,为何Adobe会放弃这么一个大市场呢? 这样无疑打击原来在flash的开发上的应用,我想很多人和我想的一样,fla ...

  4. HTML5----CSS显示半个字符

    CSS显示半个字符的基本思路: 就是一个字写两遍,分别显示一半.这里就须要用到CSS伪元素:before和:after,记住这个"伪元素"的"伪"字,表明它本来 ...

  5. 计算机思维or人的思维

    计算机领域就会有计算机领域的一些特性和一些思维方式,或者说有他自己的一些问题,须要用相应的思维方式来进行理解它,从而更好的驾驭他.有些时候遇到的一些问题,自己想却想不明确,也是由于我们没有把自己当做一 ...

  6. hdu 4044 GeoDefense (树形dp | 多叉树转二叉树)

    题目链接:hdu-4044 题意 这是一个塔防游戏,地图是一个n个编号为1-n的节点的树, 节点1是敌人的基地,其他叶子节点都是你的基地.    敌人的基地会源源不断地出来怪兽,为了防止敌人攻进你的基 ...

  7. ajax 用xml传递数据

    页面代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx. ...

  8. 导入MyEclipse项目乱码

    1.右键项目属性→text file encoding →修改为UTF-8,即可自动变成正常的.

  9. 打造强大的BaseModel(1):让Model自我描述

    前言 从事iOS开发已经两年了,从一无所知到现在能独立带领团队完成一系列APP的开发,网络上的大神给了我太多的帮助.他们无私地贡献自己的心得和经验,写出了一篇篇精美的文章.现在我也开始为大家贡献自己的 ...

  10. vb.net中常用键值

    可在代码中的任何地方用下列常数代替实际值: 常数 值 描述 vbKeyLButton 0x1 鼠标左键 vbKeyRButton 0x2 鼠标右键 vbKeyCancel 0x3 CANCEL 键 v ...