hdu1047 Integer Inquiry 多次大数相加

时间:2023-01-16 21:14:36

转载请注明出处: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&lpar;大数相加&rpar;

    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&lpar;大数相加,java&rpar;

    题目 我要开始练习一些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&lpar;大数相加&rpar;

    一.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. socket 实例化方法

      #!/usr/bin/env python # encoding: utf-8 import socket ip_port = ('127.0.0.1',9999) sk = socket.soc ...

  2. 在VS中MFC、ATL与WIN32有什么联系或区别?

    有时候遇到一些初学者问我这个问题:在VS中使用MFC和ATL与使用WIN32有什么联系或区别?通俗来说,win32是通过调用windows api去实现需要的功能.而MFC和ATL是封装好的类库,包含 ...

  3. 什么情况下用&plus;运算符进行字符串连接比调用StringBuffer&sol;StringBuilder对象的append性能好

    如果在编写代码的过程中大量使用+进行字符串评价还是会对性能造成比较大的影响,但是使用的个数在1000以下还是可以接受的,大于10000的话,执行时间将可能超过1s,会对性能产生较大影响.如果有大量需要 ...

  4. absolute之整体布局实现

    要实现如图的布局,我最先想到是将header与footer绝对定位,但是发现在移动端会出现bug,经查资料发现用absolute实现整体布局非常好,还挺简单的. .header, .footer, . ...

  5. Ext4 简单的treepanel

    转载:http://blog.csdn.net/zyujie/article/details/8208499 最近在学习Ext4,记录一些有关Ext4实现控件的方法: Ext4的treePanel和之 ...

  6. c语言数组小练习

    //查找数组中最大的值: #include<stdio.h> int main01() { , , , , , , , , , ,,}; ]; int i; ;i < ]);i++) ...

  7. 执行此安装程序之前,必须安装 32 位 Windows 映像处理组件&lpar;WIC&rpar;解决的方法

    我们在Windows Service 2003上安装 Microsoft .NET Framework4.0时常常出现以下的报错 执行此安装程序之前,必须安装 32 位 Windows 映像处理组件( ...

  8. c&num;与oracle数据库连接池

    c#与oracle数据库连接池 在做一个项目,中间要使用webservice和oracle数据库.我在服务端做了用户身份认证,也就是使用session传递用户的登陆信息.在测试时,当用户少的时候,没有 ...

  9. mysql&lowbar;建立索引的优缺点

    http://blog.csdn.net/superit401/article/details/51291603 建立索引的优缺点: 为什么要创建索引呢? 这是因为,创建索引可以大大提高系统的性能.  ...

  10. 自动布局又出问题-HPPGCTableViewCell

    [self.firstComment mas_makeConstraints:^(MASConstraintMaker *make) {        make.top.mas_equalTo(sel ...