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. VxWorks 6.9 内核编程指导之读书笔记 -- 多任务(二)

    VxWorks的系统任务 VxWorks在引导时启动的系统任务依赖于配置,有些总是运行.任务集与VxWorks的基本配置相关,很少的任务常用于可选的组件. 注意:别挂起.删除或改变任何系统任务的优先级 ...

  2. 8款最受欢迎的HTML5/CSS3应用及源码

    新的一周开始,小编也将继续为大家分享精彩的HTML5应用,还有CSS3和jQuery方面的东西.今天给大家带来的是8款最受欢迎的HTML5/CSS3应用及代码,一起来看看吧. 1.基于HTML5 Ca ...

  3. 《CSS3秘笈》备忘录

    第一部分 1.  类名称区分大小写:.special和.SPECIAL不一样 2.  :focus 是通过单击或跳格集中在某个地方 3.  ::selection 没有单冒号,被选中的文本[ 但是在I ...

  4. java随笔 乱腾腾的 一些东西

    调用requonse.getWriter()方法时可实现文本字符串数据输出,调用response.getOutputStream()方法可现实字节流数据的输出.两种输出方式threadlocal模式和 ...

  5. HDU 5024 Wang Xifeng's Little Plot(枚举)

    题意:求一个图中只有一个90°拐点的路的最大长度. 分析:枚举每一个为'.'的点,求出以该点为拐点的八种路中的最大长度,再比较所有点,得出最大长度即可. 如上样例,这样是个90°的角... 注意:最多 ...

  6. 判断不在Update Task中

    CALL FUNCTION 'TH_IN_UPDATE_TASK'   IMPORTING     IN_UPDATE_TASK = IN_UPDATE_TASK.  "0 then not ...

  7. HTML5+CSS3+JQuery打造自定义视频播放器

    来源:http://www.html5china.com/HTML5features/video/201109206_1994.html 简介HTML5的<video>标签已经被目前大多数 ...

  8. CSS居中的实现用法实例

    转载的一篇文章,讲解css内容居中的. 网上有关css 居中的文章不胜枚举,不过大多没有做系统的总结.这里分享的这篇有关css居中的文章,个人感觉不错,值得收藏. 一.水平居中1,将元素水平居中(us ...

  9. php中的常用魔术方法总结

    以下是对php中的常用魔术方法进行了详细的总结介绍,需要的朋友可以过来参考下 常用的魔术方法有:__Tostring () __Call() __autoLoad() __ clone() __GET ...

  10. this.IsMounted() is not a function

    I'm trying to build a simple React App. It retrieves data from an ajax call and renders it to the pa ...