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. [转] C++ Redistributable Package版本详解

    我们使用的程序常常都需要C++ Redistributable Package的支持.C++ Redistributable Package有众多版本,给安装带了不便. 目前(2013-12-04) ...

  2. mysql 索引建立

    如何建立mysql索引? 创建索引原则 1.左前缀原则 : mysql索引匹配会从右匹配,到遇到( >  < between like)终止.如 我们建立索引(a,b,c,d), a = ...

  3. iOS之FMDB 转载

      写的较好的博客:http://blog.csdn.net/xyz_lmn/article/details/9312837 http://www.cnblogs.com/wuhenke/archiv ...

  4. 本地win8系统部署网站遇到的问题

    网站开发环境:vs2013 .操作系统是win8.1系统. iis8   win8系统激活码:00261-30000-00000-AA825 需要部署的网站文件夹放在了桌面上,在iis里配置时,无法启 ...

  5. ORM之四:调用入口与调用示例

    一.ORM入口封装 结合上一篇文章与这里的DbProvider().Init()方法,就很明显的知道了是创建一个mssql的实例.那么在DbService的泛型方法中显示提供了单表操作与多表linq查 ...

  6. RotatingDoughnut

      RotatingDoughnut.zip

  7. Android手机中获取手机号码和运营商信息

    代码如下: package com.pei.activity; import android.app.Activity; import android.os.Bundle; import androi ...

  8. redis的hash操作在集中式session中的应用

    在集群部署时,为了高可用性的目的,往往把session进行共享,共享分为两种:session复制和集中式管理. redis在session集中式管理中可以起到比较大的作用. 制约session集中式共 ...

  9. Android View的绘制机制流程深入详解(一)

    本系列文章主要着重深入介绍Android View的绘制机制及流程,第一篇主要介绍并分析LayoutInflater的原理, 从而理解setContentView的加载原理.对于LayoutInfla ...

  10. UTF-8编码与Unicode CS2的转换

    /* Convert a UTF-8 string into a UCS-2 array. */ void tcstrutftoucs(const char *str, uint16_t *ary, ...