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在线手册布局参考图--文章详情页 article.dwt

        A.购物车 1,设置方法 程序自动读取购物车的商品数量 2,代码相关 cart.lbi 中 {insert_scripts files='transport.js'} <div clas ...

  2. .NET常用工具类集锦

    不错的地址: http://www.cnblogs.com/flashbar/archive/2013/01/23/helper.html https://github.com/chrisyanghu ...

  3. cocos2dx中android下动态更新.so文件

    作者:HU 转载请注明,原文链接:http://www.cnblogs.com/xioapingguo/p/4037595.html  因为没用lua脚本写游戏,所以每次发布出去后,发现在bug,需要 ...

  4. TableControl大小变化

    TableControl跟随Form大小变化: 选中TableControl,而不是TablePage,右侧Layout: 可以对其设置居上.居下等位置

  5. File类的基本操作之读出所有目录路径

    package org.mark.file; import java.io.File; /** * File类的基本操作之读出所有文件夹路径 * 假设给定一个文件夹,要求将此文件夹中的所有文件都列出来 ...

  6. taobao月报 ---mysql汇总

    http://blog.csdn.net/qiuyepiaoling/article/category/709481

  7. 实例源码--Android智能家居系统源码

      下载源码   技术要点:  1.Android应 用开发基础框架 2.SQLITE数据库的 使用 3.网络通信 4.GOOGLE地图模块 5.源码带有非常详 细的中文注释 ...... 详细介绍: ...

  8. JVMInternals--reference

    This article explains the internal architecture of the Java Virtual Machine (JVM). The following dia ...

  9. CSS3 动态魔方的展示

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Swift数据类型

    1.Swift中常用数据类型:首字母大写 Int.Float.Double.Bool.Character.String Array.Dictionary.元组类型(Tuple).可选类型Optiona ...