HOJ 1002题 题解

来源:互联网 发布:中国和沙特关系 知乎 编辑:程序博客网 时间:2024/05/17 23:56

  杭电OJ 1002题 题目链接: 点击打开链接

   该题需要注意的两点:

(1)题目说明了数很大,不能使用int类型,Java语言可以使用BigInteger类型

(2)注意输出格式,每两个测试用例之间输出一个空行


 本题AC示例代码如下:

  

import java.io.BufferedInputStream;import java.math.BigInteger;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(new BufferedInputStream(System.in)); int count = cin.nextInt(); for(int i=0; i<count; i++){BigInteger numOne = cin.nextBigInteger(); BigInteger numTwo = cin.nextBigInteger();  //第一行,只输出结果,不输出空行 if(i==0) { System.out.println("Case " + (i+1) + ":"); BigInteger sum = numOne.add(numTwo); System.out.println(numOne + " + " + numTwo + " = " + sum); } //第二行及之后,在输出结果之前,先输出一个空行else { System.out.println(); System.out.println("Case " + (i+1) + ":"); BigInteger sum = numOne.add(numTwo); System.out.println(numOne + " + " + numTwo + " = " + sum); } } cin.close(); } }

    欢迎评论指正讨论,不喜勿喷。

0 0