A + B Problem II

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

Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
 
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
 
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
 
Sample Input
2
1 2
112233445566778899 998877665544332211
 
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
 
Author
Ignatius.L
 #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
int t,i,k;
cin>>t;
for(k=; k<=t; k++) {
string a,b,c,m,n;
int sum,add;
cin>>a>>b;
m=a;
n=b;
int lena=a.length();
int lenb=b.length();
reverse(a.begin(),a.end());//反转字符串
reverse(b.begin(),b.end());
add=;
//模拟加法运算
for(i=; i<lena||i<lenb; i++) {
if(i<lena&&i<lenb)
sum=a[i]-''+b[i]-''+add;
else if(i<lena)
sum=a[i]-''+add;
else if(i<lenb)
sum=b[i]-''+add;
add=;
if(sum>) {
add=;
sum-=;
}
c+=sum+'';
}
if(add)
c+=add+'';
reverse(c.begin(),c.end());//还原
cout<<"Case "<<k<<":"<<endl;
cout<<m<<" + "<<n<<" = ";
cout<<c<<endl;
if(k!=t)
cout<<endl;
}
return ;
}

HDU1002 -A + B Problem II(大数a+b)的更多相关文章

  1. hdu1002 A + B Problem II(大数题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/ ...

  2. HDU1002 A + B Problem II 大数问题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java ...

  3. hdu1002 A + B Problem II[大数加法]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1002 题干 代码和解释 由题意这是一个涉及到大数的加法问题.去看了一眼大数加法的方法感觉头很大,然后突然发现Java可以流氓解决大数问题,毅 ...

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

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

  5. hdu1002 A + B Problem II(高精度加法) 2016-05-19 12:00 106人阅读 评论(0) 收藏

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

  6. [HDU1002] A + B Problem II

    Problem Description I have a very simple problem for you. Given two integers A and B, your job is to ...

  7. A + B Problem II 大数加法

    题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...

  8. A + B Problem II(大数加法)

    一直格式错误,不想改了,没A #include <iostream> #include <stdio.h> #include <string.h> #include ...

  9. HDU 1023 Train Problem II 大数打表Catalan数

    一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...

随机推荐

  1. 解决Toad for Oracle显示乱码问题

    1.查看一下数据库字符集: 使用下面语句:Select userenv('language') from dual;或者:Select name, value$ from props$;查看. 查看完 ...

  2. (转)MongoDB 实现currentOp定时捕获

    问题描述: 当分析生产环境发生的性能问题时,常常因为没有实时的依据而无从下手.那么笔者通过捕获db.currentOp()到文件,并作为定时任务,可供后续分析. 解决方法: 步骤一:Shell脚本记录 ...

  3. hdu 2955 Robberies 0-1背包/概率初始化

    /*Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. jdk、maven配置

    JDK环境变量配置1.新建系统变量 1)变量名:JAVA_HOME 变量值:C:\Program Files\Java\jdk1.7.0_15 2)变量名:CLASSPATH 变量值:.;%JAVA_ ...

  5. jQuery 判断所有图片加载完成

    对于图片的处理,例如幻灯片播放.缩放等,都是依赖于在所有图片完成之后再进行操作. 今天来看下如何判断所有的图片加载完成,而在加载完成之前可以使用 loading 的 gif 图表示正在加载中. 一.普 ...

  6. 【Qt】命令行编译Qt程序(nmake)【转】

    简述 前两节讲解了如何在Visual Studio和Qt Creator中搭建Qt开发环境,并分享了我们第一个小程序-Hello World. 下面分享如何使用命令行来编译Qt程序.当然,MSVC和M ...

  7. 利用VSCode进行.Net Core初尝试

    1.下载.Net Core,https://www.microsoft.com/net/core#windows,按照页面提示进行SDK的安装. 2.下载VsCode,https://www.visu ...

  8. MongoDB与php的配合使用 【windows版】

    通过学习了如何使用和部署MongoDB,尝试了一下如何将mongodb应用到php的程式中去. 1.预备工作 首先得准备好mongodb,并按照相关方法部署以及服务能正常运行中. 对于初学者,可以参考 ...

  9. Android SDK 更新失败

    万恶的墙,调查兵团赶紧把墙拆了.大家一起跟巨人打一架. 解决方法是改hosts文件 添加 74.125.237.1 dl-ssl.google.com ok,good job 多亏了http://bl ...

  10. Eclipse中查看JDK类库的源代码

    在Eclipse中查看JDK类库的源代码!!! 设置: 1.点 “window”-> "Preferences" -> "Java" -> & ...