A + B Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 399645    Accepted Submission(s): 77352

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

用JAVA

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n;
BigInteger a,b;
n=in.nextInt();
int i=0;
while(n>0) {
n--;
a=in.nextBigInteger();
b=in.nextBigInteger();
i++;
System.out.println("Case" + " " + i + ":");
if(n>0) {
System.out.println(a + " + " + b + " = "+a.add(b));
System.out.println();
}
else {
System.out.println(a + " + " + b + " = "+a.add(b));
}
}
}
}

C++:

要审清题意,注意输出格式!
#include<string>
#include <cstdio>
#include<iostream>
using namespace std;
string add(string a,string b)
{
int len1=a.length();
int len2=b.length();
if(len1>len2)
{
for(int i=;i<=len1-len2;i++)
b=""+b;
}
else
{
for(int i=;i<=len2-len1;i++)
a=""+a;
}
int len=a.length();
int cf=,t;
string str;
for(int i=len-;i>=;i--)
{
t=a[i]-''+b[i]-''+cf;
cf=t/;
t%=;
str=char(t+'')+str;
}
if(cf!=)
str=char(cf+'')+str;
return str;
}
int main()
{
int t;
cin>>t;
int k=;
while(t--)
{
k++;
string a,b;
cin>>a>>b;
string str;
str=add(a,b);
cout<<"Case "<<k<<":"<<endl;
cout<<a<<" + "<<b<<" = "<<str<<endl;
if(t)
cout<<endl;
}
return ;
}

(string高精度)A + B Problem II hdu1002的更多相关文章

  1. 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) ...

  2. hdoj 1002 A + B Problem II 高精度 java

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

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

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

  4. HDU 1002 A + B Problem II(高精度加法(C++/Java))

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

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

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

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

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

  7. A + B Problem II

    之前总是在查阅别人的文档,看着其他人的博客,自己心里总有一份冲动,想记录一下自己学习的经历.学习算法有一段时间了,于是想从算法开始自己的博客生涯O(∩_∩)O~~ 今天在网上看了一道大数相加(高精度) ...

  8. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  9. HDU 1002 A + B Problem II

    A + B Problem II   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted ...

随机推荐

  1. 1013 B. And

    链接 [http://codeforces.com/contest/1013/problem/B] 题意 给你一个n和x,再给n个数,有一种操作用x&a[i]取代,a[i],问使其中至少两个数 ...

  2. Java多线程的使用以及原理

    Java有两种方式实现多线程. 第一种——继承Thread类,并重写run方法 步骤: 定义类继承Thread类: 重写子类的run方法,将线程需要执行的代码写在run方法中: 创建子类的对象,则创建 ...

  3. #个人博客作业Week3——必应词典案例分析

    第一部分 调研以及评测 一.BUG分析   1. 翻译部分原文语言检测部分 1) 症状: 当选择原文语言是简体中文时,输入英文查询,程序不报错,继续翻译,选择其他类型语言也是如此. 且如果出现这种情况 ...

  4. 软件项目第一次sprint评论

    软件项目第一次sprint评论 组名:天线宝宝四人组                                   姓名:高长志 1. 组名:9-652组 项目:炸弹人游戏 对于炸弹人游戏,首先 ...

  5. let命令和块级作用域

    学习了阮一峰老师的ES6,http://es6.ruanyifeng.com/,收益良多. 一.let命令1.概念:let命令用于声明变量,和var类似,但是使用let命令所声明的变量只有在该变量所在 ...

  6. [转帖]关于网络编程中MTU、TCP、UDP优化配置的一些总结

    关于网络编程中MTU.TCP.UDP优化配置的一些总结 https://www.cnblogs.com/maowang1991/archive/2013/04/15/3022955.html 感谢原作 ...

  7. CentOS 使用SMB服务 让windows能够上传文件

    1. 新增加用户 useradd zhaobsh 2. 使用 pdbedit的方式新增加用户 pdbedit -a -u zhaobsh 3. 修改smb服务 systemctl restart sm ...

  8. 小程序的wx.onAccelerometerChange

    https://www.2cto.com/kf/201802/724174.html(copy) 也许有人会问,小程序中都是竖直app形态,要横竖屏判断有什么用?即使判断出了横屏状态,你能把小程序横过 ...

  9. elk安装最佳实践

    一.添加清华源 .x.repo<<EOF [elasticsearch-.x] name=Elasticsearch repository .x packages baseurl=http ...

  10. ubuntu python apache2 wsgi django框架

    在ubuntu上通过apatch2和wsgi部署django (亲手做过!!!) 一,我的python.django.apatch2版本: python:python -V 2.7.3 django: ...