java学习(9):杭电1002.大数处理问题

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String temp1 = null;
		String temp2 = null;
		String result = null;
		int i;

		int a = scanner.nextInt();
		for (i = 0; i < a; i++) {
			temp1 = scanner.next();
			temp2 = scanner.next();

			BigDecimal bigDecimal1 = new BigDecimal(temp1);
			BigDecimal bigDecimal2 = new BigDecimal(temp2);

			result = bigDecimal1.add(bigDecimal2).toString();
			if (i != (a - 1)) {
				System.out.println(
						"Case " + (i + 1) + ":\r\n" + bigDecimal1 + " + " + bigDecimal2 + " = " + result + "\r\n");
			}else{
				System.out.println(
						"Case " + (i + 1) + ":\r\n" + bigDecimal1 + " + " + bigDecimal2 + " = " + result);
			}

		}

	}

}
时间: 2024-10-23 03:53:25

java学习(9):杭电1002.大数处理问题的相关文章

杭电 1002 A + B Problem II(大数处理)

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 209179    Accepted Submission(s): 40226 Problem Description I have a very simple problem for you. Given two integers A and B, yo

大数A+B 【杭电-1002】 附题

/* A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 209912    Accepted Submission(s): 40404 Problem Description I have a very simple problem for you. Given two integers A and B,

杭电 1002 A + B Problem II【大数相加】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 解题思路:就是把大的数用数组存放起来,像小学的时候用竖式加法来算两个数相加那样算: 反思:思路很简单,可是有很多细节考虑不好,有时候没有进位,有时候又没有输出正确的答案,然后有时候数组长度又开小了什么的,所以还要多多练习. #include<stdio.h> #include<string.h> #define max 1000 void add(char a[],char b[

杭电1002(大数相加)

第一道大数,做这个题要细心,, #include<stdio.h> #include<string.h> int main() { int m,n; scanf("%d",&n); m=1; while(n--) { int i,j,k,t; char a[1001],b[1001],c[1001]={0}; scanf("%s %s",&a,&b); if(strlen(a)>=strlen(b)) { for

A + B Problem II(杭电1002)

/*A + B Problem II 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 case

(java实现)杭电oj 2034 人见人爱A-B

人见人爱A-B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 68543    Accepted Submission(s): 19203 Problem Description 参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减

(java实现)杭电oj2024C语言合法标识符

原题如下 C语言合法标识符 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 59747    Accepted Submission(s): 23638 Problem Description 输入一个字符串,判断其是否是C的合法标识符. Input 输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数

(java实现)杭电oj 2097 Sky数

就是简单的求出各进制之和,比较是否相等就好了 Sky数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 20822    Accepted Submission(s): 11865 Problem Description Sky从小喜欢奇特的东西,而且天生对数字特别敏感,一次偶然的机会,他发现了一个有趣的四位数2992,这个数,它的十进制

杭电1002

//此题的要点在于 把数字当字符串储存 用数组储存//计算的时候注意要减去'0',因为那是我们的字符串//在我们换算 的时候一定要加上temp 我就是因为没加 错了一个下午#include <iostream> #include<string> using namespace std; int main() { int n; cin>>n; int ui=1; while(n--){ string a,b; int sum[1001];//用来放结果 cin>&g