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 ...
随机推荐
- .NET的类型层次查看工具
上周为了快速了解一个.NET的库而需要查看其类型层次.假如要在文章中表示一个类型层次,还是用文本比较舒服,截图始终是不方便.Reflector虽然能够显示类型层次,但我无法方便的把显示出来的类型层次转 ...
- combobox的下拉框高度怎样设计合理
orry,代码如下$.extend($.fn.combobox.methods, { autoHeight : function (jq) {//combobox扩展,自动调整高度 ...
- 年末促销 Windows Azure在线充值送微软商城硬件大礼包
春节前充值,尽享云端体验, 缤纷好礼持续进行时.即日起至2015年2月13日, 充值1000元以上即享好礼.您可以查阅WindowsAzure 官网活动页面,即刻参与活动:http://www.win ...
- poj 1167 简单搜索
这题主要是注意好限定的条件 条件1:每个公交车都至少要到达两次 条件2:公交车相同时间和相同间隔是属于两种车辆 条件3:不同的车可能到达时间相同 上述都是深搜的重要条件: #include<al ...
- 使用Xcode查找项目中的中文字符串
打开”Find Navigator” 切换搜索模式到 “Find > Regular Expression” 输入@"[^"]*[\u4E00-\u9FA5]+[^" ...
- Facebook的Pop动画库相关资料
https://github.com/facebook/pop http://www.cocoachina.com/industry/20140507/8339.html http://www.ui. ...
- 《C#并行编程高级教程》第3章 命令式任务并行 笔记
Task的使用 var t1 = new Task(() => GenerateAESKeys());var t2 = new Task(() => GenerateMD5Hashes() ...
- Linux下的nginx启动、重新启动
nginx的启动命令是: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -c制定配置文件的路径,不加-nginx会自动 ...
- Sum It Up
http://acm.hdu.edu.cn/showproblem.php?pid=1258 Sum It Up Time Limit: 2000/1000 MS (Java/Others) M ...
- 多控制器之UIWindow
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...