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. Row_Number实现分页(适用SQL)

    1:首先是 select ROW_NUMBER() over(order by id asc) as 'rowNumber', * from table1 生成带序号的集合 2:再查询该集合的 第 1 ...

  2. Linux系统目录分析

    Linux系统目录分析 /bin :系统指令目录(如ls.cp.mv等指令) /dev :系统设备目录 /home :系统用户的家,每一个系统用户都在此目录下有一个自己的家,每次登录时,系统都会自动登 ...

  3. C++ 单链表基本操作

    链表一直是面试的高频题,今天先总结一下单链表的使用,下节再总结双向链表的.本文主要有单链表的创建.插入.删除节点等. 1.概念 单链表是一种链式存取的数据结构,用一组地址任意的存储单元存放线性表中的数 ...

  4. MySQL中,把varchar类型转为date类型

    如下表: 先使用str_to_date函数,将其varchar类型转为日期类型,然后从小到大排序 语法:select str_to_date(class_time,'%Y%m%d %H:%i:%s') ...

  5. 理解 pkg-config 工具

    引用了别人的文章:http://www.chenjunlu.com/2011/03/understanding-pkg-config-tool/ 你在 Unix 或 Linux 下开发过软件吗?写完一 ...

  6. 【Qt】Qt之自定义界面(实现无边框、可移动)【转】

    简述 UI设计是指对软件的人机交互.操作逻辑.界面美观的整体设计.好的UI设计不仅是让软件变得有个性.有品位,还要让软件的操作变得舒适简单.自由,充分体现软件的定位和特点. 爱美之心人皆有之.其实软件 ...

  7. PHP CI 查询条件大全

    php CI 框架 this->db->where() 条件 PHP 5 版本 $this->db->where() 接受可选的第三个参数.如果你将它设置为 FALSE, Co ...

  8. 用MySQL log调试程序

    打开my.ini文件 在[mysqld]的下面加上log = c:/mysql_query.log.txt重启mysql 以后你用可以用editplus查看你运行的sql了,不用在程序里一句句的用lo ...

  9. Oracle RAC Failover

    Oracle  RAC 同时具备HA(High Availiablity) 和LB(LoadBalance). 而其高可用性的基础就是Failover(故障转移). 它指集群中任何一个节点的故障都不会 ...

  10. WPF-控件-编辑圆角TextBox

    使用模板 代码如下: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xm ...