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. vue项目中引入bootstrap

    (1)引入Jquery文件,需要在bootstrap.min.js 之前引入. 1.npm install jquery --save-dev 2. plugins: [ new webpack.Pr ...

  2. CSS通过设置position定位的三种常用定位

    CSS中可以通过设置为元素设置一个position属性值,从而达到将不同的元素显示在不同的位置,或者固定显示在某一个位置,或者显示在某一层页面之上. position的值可以设为relative,ab ...

  3. css过渡笔记

    3D     http://fangyexu.com/tool-CSS3Inspector.html <!DOCTYPE html> <html lang="en" ...

  4. python之函数的参数

    1.位置参数: 例如计算一个整数的平方: def power(x) return x * x 显然参数x就是一个位置参数,如果要是计算5*5*5..............*5 ,这个函数就太麻烦了, ...

  5. 规划行业GIS云平台“城智图”上线运行

    首先祝各位朋友中秋节快乐! 城智图(www.imapcity.com)是远景GIS云平台的首个应用项目,它以全新的方式为规划部门提供地理信息服务,改变了以前规划部门只有CAD成果数据,难以查阅.深入挖 ...

  6. Solr常用操作命令

    1. 新建collection ./solr create_collection -c collection_vip -d /opt/lucidworks-hdpsearch/solr/server/ ...

  7. lodop 代码注释

    LODOP.SET_PRINT_PAGESIZE(1,1000,1500,"");  /*1,纵向输出;1000,宽度;1500,高度*:单位为0.1毫米/LODOP.ADD_PR ...

  8. java 内存分析之static

    源码: 内存分析: 源码: 静态方法:   用static 声明的方法为静态方法,在调用该方法时,不会将对象的引用传递给它,所以在static 方法中不可访问非static 的成员.   可以通过对象 ...

  9. redis介绍(2)简单安装

    我分两种方式讲解 window 下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你系统平台的实 ...

  10. JS + jQuery 实现元素自动滚动到底部,兼容IE、FF、Chrome

    HTML代码: <ul class="tasklog-dialog-ul" id="auto_to_bottom"> <li>删除虚拟机 ...