hdu1047 Integer Inquiry 多次大数相加
转载请注明出处:http://blog.csdn.net/u012860063
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047
``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.)
The final input line will contain a single zero on a line by itself.
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.
1 123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
370370367037037036703703703670
纯大树相加:
代码例如以下:
#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 多次大数相加的更多相关文章
- hdu1047 Integer Inquiry
/* Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu acm-1047 Integer Inquiry(大数相加)
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- UVa 424 Integer Inquiry 【大数相加】
解题思路:因为给定的数据是多组,所以我们只需要多次做加法就可以了,将上一次的和又作为下一次加法运算的一个加数. 反思:还是题意理解不够清楚,最开始以为只是算三个大数相加,后来才发现是多个,然后注意到当 ...
- POJ 1503 Integer Inquiry(大数相加,java)
题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...
- (大数 string) Integer Inquiry hdu1047
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ 1503 Integer Inquiry(大数相加)
一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...
- HDU 1047 Integer Inquiry 大数相加 string解法
本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...
- Integer Inquiry【大数的加法举例】
Integer Inquiry Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27730 Accepted: 10764 ...
- Java大数相加-hdu1047
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047 题目描述: 题意有点绕,但是仔细的读了后就发现是处理大数相加的问题.注意:输入数据有多组,每组输 ...
随机推荐
- String构造函数originalValue.length>size 它发生
最近观看Jdk6于String源代码被发现String这种施工方法有.源内容如下面: public String(String original) { int size = original.coun ...
- 从电商秒杀与抢购谈Web系统大规模并发
从电商秒杀与抢购谈Web系统大规模并发 http://www.iamlintao.com/4242.html 一.大规模并发带来的挑战 在过去的工作中,我曾经面对过5w每秒的高并发秒杀功能,在这个过程 ...
- Binary Tree Inorder Traversal(转)
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tr ...
- SQL Server 2008性能故障排查(二)——CPU
原文:SQL Server 2008性能故障排查(二)--CPU 承接上一篇:SQL Server 2008性能故障排查(一)--概论 说明一下,CSDN的博客编辑非常不人性化,我在word里面都排好 ...
- OSChina 的URL类的源代码重写过程
此代码是 oschina 到手柄形状像 http://www.oschina.net/p/tomcat 这种URL 此类已经废弃,改用 http://www.oschina.net/code/snip ...
- [SQL Server优化]善用系统监视器,确定系统瓶颈
原文:[SQL Server优化]善用系统监视器,确定系统瓶颈 来自: http://hi.baidu.com/solorez/blog/item/f82038fa0e71b78d9e51468c.h ...
- C++,Python,Go对照学习-01
好吧其实学Go只是为了好玩,只是为了好玩,学习过程中不免会把其他我懂的语言的思维定势和习惯带进来,由此有了这篇对照学习的记录,就当是留下学习的脚印吧. 这里所提及的语言特性在C++指最新的C++11标 ...
- openstack 网络架构 nova-network + neutron
openstack网络架构(nova-network/neutron) openstack网络体系中,网络技术没有创新,但用到的技术点很庞杂,包含bridge.vlan.gre.vxlan.ovs.o ...
- M、V、C
概述 Model-View-Controller(MVC),即模型-视图-控制器. MVC将软件系统分成三大部分:Model,View,Controller,三个部分通过某种机制通信 M.V.C的职能 ...
- [.Net Tools] 超強大的封裝工具 Advanced Installer
原文:[.Net Tools] 超强大的封装工具Advanced Installer 日前在网路上晃到这家公司的产品http://www.advancedinstaller.com/,就直接下载并且安 ...