转载请注明出处:http://blog.csdn.net/u012860063

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047

Problem 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.)

 
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
1 123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
 
Sample Output
370370367037037036703703703670
 
Source

纯大树相加:

代码例如以下:

#include <cstdio>
#include <cstring>
int sum[147];
char s[147];
void Add( char ss[])
{
int len = strlen(ss);
int z = 1;
for(int i = len - 1 ; i >= 0 ; i-- )
{
sum[z] +=(ss[i]-'0');
sum[z+1] +=sum[z]/10;
sum[z]%=10;
z++;
}
} int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
memset(sum,0,sizeof(sum));
while(scanf("%s",s)&&s[0]!='0')
{
Add(s);
}
int flag = 0;
for(int i = 147; i > 1 ; i-- )
{
if(flag == 0 && sum[i] == 0)
continue;
else
{
flag = 1;
printf("%d",sum[i]);
}
}
printf("%d\n",sum[1]);
if(t != 0)
printf("\n");
}
}
return 0;
}

hdu1047 Integer Inquiry 多次大数相加的更多相关文章

  1. hdu1047 Integer Inquiry

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

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

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

  3. UVa 424 Integer Inquiry 【大数相加】

    解题思路:因为给定的数据是多组,所以我们只需要多次做加法就可以了,将上一次的和又作为下一次加法运算的一个加数. 反思:还是题意理解不够清楚,最开始以为只是算三个大数相加,后来才发现是多个,然后注意到当 ...

  4. POJ 1503 Integer Inquiry(大数相加,java)

    题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...

  5. (大数 string) Integer Inquiry hdu1047

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

  6. POJ 1503 Integer Inquiry(大数相加)

    一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...

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

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

  8. Integer Inquiry【大数的加法举例】

    Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27730   Accepted: 10764 ...

  9. Java大数相加-hdu1047

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047 题目描述: 题意有点绕,但是仔细的读了后就发现是处理大数相加的问题.注意:输入数据有多组,每组输 ...

随机推荐

  1. Cocos2d-x 单点触摸--让我们用手指动起来的精灵

    转载请注明出处:http://blog.csdn.net/oyangyufu/article/details/25656673 效果图: CCTouch类装载了触摸点的信息.包含触摸点的横纵坐标值和触 ...

  2. Ini文件帮助类

    .ini文件是什么 .ini 文件是Initialization File的缩写,就是初始化文件.在Windows系统中,其是配置文件所采用的存储格式(主要是system.ini,win.ini,sy ...

  3. 网络视频播放器插件ckplayer使用-简介

    ckplayer插件下载:http://pan.baidu.com/s/12HYH4(假设不见了,下载您自己的地址,下载后添加到站点根文件夹) ******特别提醒:解压后不要忘了把js文件夹也加入到 ...

  4. LeetCode——Pascal&#39;s Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  5. c#基于这些,你已经看到了?(一)-----谁才刚刚开始学习使用

    1.注视(不要写的目光是流氓,从废话名盲人) '///'一般用于目光功能.凝视类. 2.热键 ctrl+k+d(有语法错误无法进行对齐) ctrl+j(高速弹出仅仅能提示) shift+end,shi ...

  6. 怎么样ubuntu 64 11.04 在执行32位程序

    上网一查非常多的信息,头发上的今天ubuntu 64 11.04 在执行32位程序安装ia32-libs包,可执行例如,下面的命令.但提示无法安装 apt-get install ia32-libs ...

  7. Java读书笔记三(字符串)

    1.介绍 本篇博客将对JAVA中的字符串类的基本知识进行介绍.主要字符串类的一些经常用法等内容. 2.字符串对象的创建 1.有两种形式.可是在开发中常常习惯于String 变量名的形式来进行操作. & ...

  8. 基于docker构建jenkins和svn服务(转)

    码农们很定都知道svn的重要性,机器坏掉丢代码的惨痛教训想必很多人都有. jenkins可能很多人都不了解.这是一个持续集成的工具,在敏捷开发领域很流行:跟svn结合可以实现定期build.check ...

  9. Java 新特性(2) - JDK6 新特性

    http://freesea.iteye.com/blog/160133 JDK6的新特性之一_Desktop类和SystemTray类 JDK6的新特性之二_使用JAXB2来实现对象与XML之间的映 ...

  10. Spring配置与第一Spring HelloWorld

    林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka 本文将主讲了Spring在Eclipse下的配置,并用Spring执行了第一个HelloWo ...