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. hdu 1263 水果 结构的排序+sort自定义排序

    水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  2. swap函数

    #include<iostream> using namespace std; void swap(int& a,int& b){ int t=a; a=b; b=t; } ...

  3. 原型设计(“留拍”Axure整体操作过程)

    使用 Axure 来设计原型[通过 视频(自己录视频上传到优酷网站) 来介绍 “留拍” 的基本 原型 ,后续再 美化界面 和 补充 详细功能]: 请点击下图的播放按钮来弹出视频(通过URL连接):

  4. 纯MarkDown博客阅读体验优化

    今天鼓捣了一天纯MarkDown书写的博客样式的美化,事实证明图表较多的MarkDown撰写的博文一样可以展现出非常漂亮的效果.为了让纯MarkDown书写的博客有一个干净舒服的阅读体验,我主要针对博 ...

  5. FreeMaker使用HashMap

    private Map<String, Object> variables; <input type="hidden" id="tongzhisbm&q ...

  6. Linux大页内存管理等---菜鸟初学

    1. 查看linux的内存情况: free -m 2. 查看是否开启大页的方法: cat /proc/meminfo |grep -i HugePage AnonHugePages: 276480 k ...

  7. [转帖] .NET FrameWork 版本的确定方法

    检测电脑安装的net framework版本   https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx To find .N ...

  8. PSP(5.4——5.10)以及周记录

    1.PSP 5.4 14:00 17:00 70 110 讨论班 A Y min 5.5 10:00 16:50 125 285 Cordova A Y min 5.6 13:30 15:00 35 ...

  9. pandas切片使用和column赋值

    #-*- coding: utf-8 -*- #对数据进行基本的探索 #返回缺失值个数以及最大最小值 import pandas as pd datafile= '../data/air_data.c ...

  10. 在DBGrid中,单击单元格选择整行,双击又可编辑单元格

    在设计过程中,有时候数据较大量,field 较多的时候,只是点击单元格可能会对某个field的数据误操作(如数据错行),为此才会想到这个问题,解决办法如下:点击单元格就改当前行颜色. 首先DBGRID ...