HDU1002 -A + B Problem II(大数a+b)

时间:2022-09-24 07:38:35

  

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 &plus; B Problem II&lpar;大数题&rpar;

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

  2. HDU1002 A &plus; 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 &plus; B Problem II&lbrack;大数加法&rsqb;

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

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

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

  5. hdu1002 A &plus; B Problem II&lpar;高精度加法&rpar; 2016-05-19 12&colon;00 106人阅读 评论&lpar;0&rpar; 收藏

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

  6. &lbrack;HDU1002&rsqb; A &plus; 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 &plus; B Problem II 大数加法

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

  8. A &plus; B Problem II&lpar;大数加法)

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

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

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

随机推荐

  1. codevs哈希水题

    1230 多重hash练习一下,不用也可以 // // main.cpp // codeves1230 // // Created by Candy on 9/29/16. // Copyright ...

  2. java&lowbar;final关键字的使用

    final : 最终.作为一个修饰符,1,可以修饰类,函数,变量.2,被final修饰的类不可以被继承.为了避免被继承,被子类复写功能.3,被final修饰的方法不可以被复写.4,被final修饰的变 ...

  3. Codeforces Round &num;109 &lpar;Div&period; 2&rpar; E&period; Double Profiles hash

    题目链接: http://codeforces.com/problemset/problem/155/E E. Double Profiles time limit per test 3 second ...

  4. coreseek&lpar;sphinx&rpar;错误&colon;WARNING&colon; attribute &&num;39&semi;id&&num;39&semi; not found - IGNORING

    coreseek(sphinx)错误:WARNING: attribute 'id' not found - IGNORING原因及解决方法 coreseek(sphinx)建立索引时提示错误: WA ...

  5. 198&period; House Robber&comma;213&period; House Robber II

    198. House Robber Total Accepted: 45873 Total Submissions: 142855 Difficulty: Easy You are a profess ...

  6. display&colon; inline-block兼容性写法

    display:inline-block;*display:inline;*zoom:1;

  7. JAVA通过I&sol;O流复制文件

    JAVA通过I/O流复制文件 本文是对字节流操作,可以多音频视频文件进行操作,亲测有效. 个人感觉这个东西就是靠记的, 没什么好解释的,,,, import java.io.File; import ...

  8. C&plus;&plus; 值类型和引用类型传递示例

    // win32test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" void swap_point(int * &a , in ...

  9. PHP 中 config&period;m4 的探索

    PHP 中 config.m4 的探索 最近在看php扩展相关的东西,虽然来来回回编辑了好多次config.m4,并且也在技术社区看到了 config.m4是什么?什么作用? 类的问题,但是还是觉得有 ...

  10. DBUtils - Python数据库连接池

    flask没有ORM操作这一功能, 但是想要操作数据库怎么办呢, 使用第三方包DBUtils 查询需要SQL原生语句! DBUtils 第一步还是要下载 使用pycharm直接搜索DBUtils fr ...