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. 20150309—bs的保存状态

    http:保存状态方式,传值方式 session:(会话) 默认过期时间20分钟(20分内无任何操作自动销毁),针对用户独立,一般用来存储少量信息的 存值:session[“name”]=data;( ...

  2. javaScript中的数组迭代方法

    ECMAScript5为数组定义了5个迭代方法. 每个方法都接收两个参数:要在每一项上运行的函数  和  (可选的)运行该函数的作用域对象. 传入这些方法中的函数会接收三个参数:数组项的值,该项在数组 ...

  3. 7款个性化jQuery/HTML5地图插件

    现在我们经常会用到一些地图应用,无论是在网页上还是手机App中,地图貌似是一个不可或缺的应用.本文将带领大家一起来看看一些基于jQuery和HTML5的个性化地图插件,有几款地图比较实用,有些则是具有 ...

  4. 如何在Mac下使用TF/SD 卡制作Exynos 4412 u-boot启动盘

    /** ****************************************************************************** * @author    Maox ...

  5. 方便实用的jQuery checkbox复选框全选功能

    // 主复选框 <input type="checkbox" id="ck" name="ckAll">// 子复选框项 < ...

  6. 两个Activity之间的交互startActivityForResult的使用

    代码如下: package com.zzw.teststartintentforrequest; import android.app.Activity; import android.content ...

  7. 禁用cookie后

    服务器为某个访问者创建一个内存区域,这个就是所谓的session,这个区域的存在是有时间限制的,比如30分钟,这块区域诞生的时候,服务器会给这个区域分配一个钥匙,只有使用这个钥匙才能访问这个区域,这个 ...

  8. c# 刻度:毫米 英寸 像素转换

    从目前所掌握的资料来看,c#程序中将毫米转换像素的方法无非两种: 第一种: 1: /// <summary> 2: /// 以毫米为单位的显示宽度 3: /// </summary& ...

  9. 一道关于比赛胜负的Sql查询题目

    以前做过一道题目,一直没有来得及总结下来.贴图: 记得以前曾经找到了两种方法,今天试了一下,还是可以的,贴出过程: 下面是具体的查询方法: 原来放的是图片,今天又练习了一下,附代码: create T ...

  10. Zend-MVC事件

    Zend\Mvc\MvcEvent继承自Zend\EventManager\Event,在Zend\Mvc\Application::bootstrap()执行时触发.如果你的控制器实现了Zend\M ...