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 ...
随机推荐
- Android-AttributeSet详解
public interface AttributeSet { /** * Returns the number of attributes available in the set. * * @re ...
- 【HDOJ】2062 Subset sequence
这道题目非常好,饶了点儿圈子.我的思路是,先按照组排列.例如,1 2 31 2 2 1 3 11 2 3 2 1 3 ...
- 【HDOJ】1076 An Easy Task
水题,如题. #include <stdio.h> #define chk(Y) (Y%4==0 && Y%100!=0) || Y%400==0 int main() { ...
- 获取本机的ip
https://4sysops.com/archives/ipv6-tutorial-part-6-site-local-addresses-and-link-local-addresses/ In ...
- 结构体typedef struct dtuple_struct dtuple_t;
/** Structure for an SQL data tuple of fields (logical record) */ struct dtuple_struct { ulint info_ ...
- bzoj1823
第一道2sat, 其实2sat问题不难,只要记住一个:通过“推导出”连边 什么意思呢?就是一般题目中的变量都有两个状态,只能取一个,我们定义为true和false 对于每一个变量i,我们都拆成两个点, ...
- Win32下 Qt与Lua交互使用(二):在Lua脚本中使用Qt类
话接上篇.成功配置好Qt+Lua+toLua后,我们可以实现在Lua脚本中使用各个Qt的类.直接看代码吧. #include "include/lua.hpp" #include ...
- 宣布 Azure Backup 支持备份 Windows Server 2008
Giridhar Mosay 云 + Enterprise项目经理 AzureBackup已支持最新的 Windows Server 操作系统,例如 Windows Server 2008R2. ...
- ASP.NET MVC 開發心得分享 (21):Routing 觀念與技巧
ASP.NET MVC 預設在 Global.asax 所定義的 RegisterRoutes 方法中可以輕易的定義你希望擁有的網址格式,嚴格上來講這並非 ASP.NET MVC 的專利,而是從 AS ...
- seg格式文件的分析
s ,r, c1, c2 第r行的c1列到 c2列的值为s