Integer Inquiry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23291    Accepted Submission(s): 6564

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
 
代码如下:
#include<bits/stdc++.h>
using namespace std;
string add(string str1,string str2)
{
int l1=str1.length();
int l2=str2.length();
if(l1>l2)
{
for(int i=;i<l1-l2;i++)
{
str2=""+str2;
}
}else if(l1<l2)
{
for(int i=;i<l2-l1;i++)
{
str1=""+str1;
}
}
l1=str1.length();
string str3;
int c=;
for(int i=l1-;i>=;i--)
{
int temp=str1[i]-''+str2[i]-''+c;
c=temp/;
temp=temp%;
str3=char(temp+'')+str3;
}
if(c!=)
{
str3=char(c+'')+str3;
}
return str3;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
string str;
string sum="";
while(cin>>str)
{
if(str=="")
break;
sum=add(sum,str);
}
cout<<sum<<endl;
if(n>)
printf("\n");
}
return ;
}

HDU1047(多个大数相加)的更多相关文章

  1. Java大数相加-hdu1047

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

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

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

  3. 用字符串模拟两个大数相加——java实现

    问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...

  4. 随机数组&大数相加

    随机生成10个数,填充一个数组,然后用消息框显示数组内容,接着计算数组元素的和,将结果也显示在消息框中 一,      设计思路: 先生成随机数数组,再将数组保存在一个字符串中,然后将数组各数字加和, ...

  5. java-两个大数相加

    题目要求:用字符串模拟两个大数相加. 一.使用BigInteger类.BigDecimal类 public static void main(String[] args) { String a=&qu ...

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

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

  7. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  8. Linux C/C++ 编程练手 --- 大数相加和大数相乘

    最近写了一个大数相乘和相加的程序,结果看起来是对的.不过期间的效率可能不是最好的,有些地方也是临时为了解决问题而直接写出来的. 可以大概说一下相乘和相加的解决思路(当然,大数操作基本就是两个字符串的操 ...

  9. hdu1002大数相加

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  10. 基于visual Studio2013解决C语言竞赛题之1077大数相加

        题目 解决代码及点评 /************************************************************************/ /* ...

随机推荐

  1. BZOJ4144: [AMPPZ2014]Petrol(最短路 最小生成树)

    题意 题目链接 Sol 做的时候忘记写题解了 可以参考这位大爷 #include<bits/stdc++.h> #define Pair pair<int, int> #def ...

  2. 移动端h5实现拍照上传图片并预览&webuploader

    .移动端实现图片上传并预览,用到h5的input的file属性及filereader对象:经测除了android上不支持多图片上传,其他基本ok实用: 一:先说一下单张图片上传(先上代码): html ...

  3. 报表在IBM AIX系统下resin部署

     报表是用java开发的,具有良好的跨平台性.不仅可以应用在windows.linux.操作系统,还可以应用在AIX等等的unix操作系统.在各种操作系统上部署过程有一些差别.下面说一下在AIX操 ...

  4. 读写JSON作配置文件

    个人不太喜欢XML,于是找了JSON来做配置,JSON虽然有很多引号,但这种key-value的形式,非常符合我的思维,就像是一个萝卜一个坑.最近在读写JSON文件,需要注意两个问题. 中文乱码: 直 ...

  5. python学习手册中的一些易忘的点(前三部分)

    1.ubuntu下让python脚本可直接运行: test.py文件(后缀可省)#!/usr/bin/pythonprint('wwwww') sudo chmod +x ./test.py (sud ...

  6. 团队项目个人进展——Day05

    一.昨天工作总结 冲刺第五天,学习了官方文档说明,学习并但是并未实现地图的放大与缩小 二.遇到的问题 对一些框架和API不太熟悉 未实现地图的放大与缩小 三.今日工作规划 深入学习有关视频与文档说明

  7. 使用cnpm install提示package not found

    使用cnpm install 的时候提示Can't find package. 在cnpm package里能搜索到scratch-audio的包,但版本是0.1.0-prerelease.20190 ...

  8. 分别用C/C++ 和 C#实现简单的观察者模式

    网上找了很多关于观察者模式的代码例子和文章,都写的比较复杂,我个人还是喜欢从易到难,今天自己参考网上资料,也写了一个简单观察者模式的例子,简单的复习了一下Observer 模式,Observer 模式 ...

  9. MDT配置数据库

    连接数据库可以使用数据库账户和Windows集成身份验证两种方法:使用数据库账户:1.连接数据库时选择TCP/IP2.在数据库中添加相应规则后,配置数据库3.在CustomSettings.ini文件 ...

  10. spring-boot-jpa 自定义查询工具类

    1.pom文件中添加如下配置 <dependency> <groupId>org.springframework.boot</groupId> <artifa ...