hdu1002大数相加
A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 313689 Accepted Submission(s):
60742
integers A and B, your job is to calculate the Sum of A + B.
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.
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.
1 + 2 = 3
112233445566778899 + 998877665544332211 = 1111111111111111110
import java.math.BigInteger;
import java.text.Bidi;
import java.util.Scanner;
public class Main1002 {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
int n=cin.nextInt();
int t=0;
while(n-->0){
BigInteger b=cin.nextBigInteger();
BigInteger c=cin.nextBigInteger();
BigInteger d=new BigInteger("0");
d=b.add( c);
System.out.println("Case"+" "+(++t)+":");
System.out.println(b+" "+"+"+" "+c+" "+"="+" "+d);
if(n!=0)
System.out.println();
}
}
}
}
感觉用java 做大数相加的这个题好简单呀
hdu1002大数相加的更多相关文章
- HDU-1002.大数相加(字符串模拟)
本题大意:给出两个1000位以内的大数a 和b,让你计算a + b的值. 本题思路:字符串模拟就能过,会Java的大佬应该不会点进来...... 参考代码: #include <cstdio&g ...
- HDU1002 大数相加
#include <iostream> #include <iostream> #include <iomanip> #include<string> ...
- hdu1002 大数相加问题
这个题对于 几个月前的我简直是噩梦 好在磕磕绊绊终于写出来了 由于自己的问题 还被巨巨嘲讽了 1 1.#include<stdio.h> 2 2.#include<string. ...
- hdu acm-1047 Integer Inquiry(大数相加)
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 用字符串模拟两个大数相加——java实现
问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...
- 随机数组&大数相加
随机生成10个数,填充一个数组,然后用消息框显示数组内容,接着计算数组元素的和,将结果也显示在消息框中 一, 设计思路: 先生成随机数数组,再将数组保存在一个字符串中,然后将数组各数字加和, ...
- java-两个大数相加
题目要求:用字符串模拟两个大数相加. 一.使用BigInteger类.BigDecimal类 public static void main(String[] args) { String a=&qu ...
- POJ 1503 Integer Inquiry(大数相加,java)
题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
随机推荐
- 《BackboneJS框架的技巧及模式》(4)完结篇
<BackboneJS框架的技巧及模式>(4)完结篇 本文紧接第二部分:<BackboneJS框架的技巧及模式(3)> 作者:chszs,转载需注明.博客主页:http://b ...
- Understanding Network Class Loaders
By Qusay H. Mahmoud, October 2004 When Java was first released to the public in 1995 it came wit ...
- Java 异常类层次结构
在Java中,异常分为受检查的异常,与运行时异常. 两者都在异常类层次结构中. 下面的图展示了Java异常类的继承关系. 图1 粉红色的是受检查的异常(checked exceptions),其必须被 ...
- bzoj3165 1568
1568是3165的弱化版,发的代码是3165的这道题完全没想出来,是看wyl大神的题解http://hi.baidu.com/wyl8899/item/2deafd3a376ef2d46d15e99 ...
- c#反射重载方法(发现不明确的匹配)
GetMethod(string name) 在反射重载方法时,如果调用此重载方法,会产生 发现不明确的匹配 的错误. 解决方案如下: GetMethod("MethodName" ...
- Samba nsswitch/pam_winbind.c文件输入验证漏洞
漏洞名称: Samba nsswitch/pam_winbind.c文件输入验证漏洞 CNNVD编号: CNNVD-201312-047 发布时间: 2013-12-05 更新时间: 2013-12- ...
- 教程 打造OS X Mavericks原版 EFI Clover 引导安装
自从 Mavericks 10.9 发布DP版到现在的GM版以来,以前Clover引导原版InstallESD.dmg方式安装原版的方法已经不能使用,而且已经不能引导安装了,所以从GM版发布以前,终于 ...
- 使用PowerDesigner建立数据库模型
转自:http://www.cnblogs.com/tonyepaper/archive/2008/02/12/1067260.html 1. 打开PowerDesigner,点击File ...
- selenium-ide学习
最近想把selenium给系统的学习下.主要因为它开源,且适配多个浏览器多种语言. selenium主要由selenium-ide.selenium1.selenium2.selenium guird ...
- Java和C++的区别
这是一个Java语言和C++语言之间的比较. 目录 [隐藏] 1 设计目标 2 语言特性 2.1 语法 2.2 语义 2.3 资源管理 2.4 库 2.5 运行时 2.6 模板 vs. 泛型 2.7 ...