【PAT甲级 大整数BigInteger】1065 A+B and C (64bit) (20 分) Java 全部AC

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/sinat_42483341/article/details/100568333

题目

在有些方面,比如大整数的处理,不得不佩服Java,好用没的说,像开挂一样
在这里插入图片描述


题解 Java

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		// 总行数
		int total = Integer.parseInt(sc.nextLine());

		// 两数相加 与第三个数比较
		for (int i = 0; i < total; i++) {
			String str = sc.nextLine();
			String[] strArr = str.split(" ");
			BigInteger big1 = new BigInteger(strArr[0]);
			BigInteger big2 = new BigInteger(strArr[1]);
			BigInteger big3 = new BigInteger(strArr[2]);

			BigInteger sum = big1.add(big2);
			if (sum.compareTo(big3) > 0) {// sum>big3
				System.out.println("Case #" + (i + 1) + ": true");
			} else {
				System.out.println("Case #" + (i + 1) + ": false");
			}
		}
	}
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/sinat_42483341/article/details/100568333