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

題目

在有些方面,比如大整數的處理,不得不佩服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");
			}
		}
	}
}

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章