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. cf121C. Lucky Permutation(康托展开)

    题意 题目链接 Sol 由于阶乘的数量增长非常迅速,而\(k\)又非常小,那么显然最后的序列只有最后几位会发生改变. 前面的位置都是\(i = a[i]\).那么前面的可以直接数位dp/爆搜,后面的部 ...

  2. 2017年CCF大数据与计算智能大赛,梳理总结新鲜出炉啦~~~

    0 序言 比赛已经过去一段时间,现在才来写总结似乎有点儿晚,但是挡不住内心发出的强烈呼唤的声音,所以决定静下心来梳理一遍,查缺补漏. 参赛契机: 2017年9月偶然在学校的官方微信推送中看到2017年 ...

  3. HiveSql调优经验

    背景 在刚使用hive的过程中,碰到过很多问题,任务经常需要运行7,8个小时甚至更久,在此记录一下这个过程中,我的一些收获 join长尾 背景 SQL在Join执行阶段会将Join Key相同的数据分 ...

  4. Spring Boot -01- 快速入门篇(图文教程)

    Spring Boot -01- 快速入门篇(图文教程) 今天开始不断整理 Spring Boot 2.0 版本学习笔记,大家可以在博客看到我的笔记,然后大家想看视频课程也可以到[慕课网]手机 app ...

  5. 选择 Java 编写 iOS 与 安卓 App的八大理由

    [编者按]本文作者为 RoboVM 的 CEO 兼联合创始人 Henric Müller,主要介绍选用 Java 编写移动应用的八大理由.文章系国内 ITOM 管理平台 OneAPM 编译呈现. 在过 ...

  6. sqlserver的资源调控器

    参考SQL Server2014管理最佳实战,所做的笔记. 1:创建资源池 use master go create resource pool poolAdhoc with ( min_cpu_pe ...

  7. 关于jquery的serialize方法转换空格为+号的解决方法

    jquery的 serialize()方法,可以对表单项进行序列化,这本来是很方便的一个功能:但是实际使用中去发现了如下问题:例如:< textarea name="content&q ...

  8. iOS设计模式 - 访问者

    iOS设计模式 - 访问者 原理图 说明 表示一个作用于某对象结构中的各元素的操作,它使你可以在不改变各元素类的前提下定义作用于这些元素的新操作. 1.Visitor 抽象访问者角色,为该对象结构中具 ...

  9. 裸机恢复 (BMR) 和系统状态恢复

    DPM 将系统保护数据源视为两个组成部分 – 裸机恢复 (BMR) 和系统状态保护. BMR 涉及保护操作系统文件和重要卷上的所有数据,用户数据除外. 系统状态保护涉及保护操作系统文件. DPM 使用 ...

  10. mysql 8.0.11 安装(windows)

    mysql本地安装(windows) 一.安装包下载 从官网下载安装包,地址:https://dev.mysql.com/downloads/mysql/ 二.配置 解压到本地,然后在目录下新建my. ...