天天看点

蓝桥试题 算法提高 高精度减法 JAVA

资源限制

时间限制:1.0s 内存限制:256.0MB

问题描述

  高精度减法

输入格式

  两行,表示两个非负整数a、b,且有a > b。

输出格式

  一行,表示a与b的差

样例输入

1234567890987654321

9999

样例输出

1234567890987644322

思路:这么大的数字就直接上BigInteger就可。

补充BigInteger的知识点:

add 加

subtract 减

multiply 乘

divide 除

divideAndRemainder 返回商和余数数组

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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger a=scanner.nextBigInteger();
		BigInteger b=scanner.nextBigInteger();
		System.out.println(a.subtract(b));      // 输出结果,a-b
	}
}

           

小剧场:不如大大方方向前。It’s better to be generous.