PAT1065. A+B and C (64bit)

PAT1065. A+B and C (64bit)

题目大意

给定三个 64 位整数 a, b, c. 问 a + b > c 是否成立

思路

一道考察字符串处理的题, 可以用Java大整数类水过, 但是需要加速挂, 否则会超时.

代码

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.StringTokenizer;

class Reader {
		static BufferedReader reader;
		static StringTokenizer tokenizer;

		static void init(InputStream input) {
			reader = new BufferedReader(
					new InputStreamReader(input));
			tokenizer = new StringTokenizer("");
		}

		static String next() throws IOException{
			while(!tokenizer.hasMoreTokens()) {
				tokenizer = new StringTokenizer(
						reader.readLine());
			}
			return tokenizer.nextToken();
		}
		static int nextInt() throws IOException {
	        return Integer.parseInt( next() );
	    }

	    static double nextDouble() throws IOException {
	        return Double.parseDouble( next() );
	    }
        static BigInteger nextBigInteger() throws IOException {
            return new BigInteger(next());
        }
}

public class Hello {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Reader.init(System.in);
		int nCase = Reader.nextInt();
		for(int i = 1; i <= nCase; i++) {
			BigInteger a = Reader.nextBigInteger();
			BigInteger b = Reader.nextBigInteger();
			BigInteger c = Reader.nextBigInteger();
			System.out.print("Case #" + i + ": ");
			if(a.add(b).compareTo(c) > 0)
				System.out.println("true");
			else
				System.out.println("false");
		}
	}

}

posted @ 2017-11-07 21:35  1pha  阅读(139)  评论(0编辑  收藏  举报