• 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");
    		}
    	}
    
    }
    
    
  • 相关阅读:
    事务
    一、python 基础之基础语法
    二、python 中五种常用的数据类型
    三、python函数详解
    四、 面向对象(一)
    五、面向对象(二)——继承与重写
    六、异常处理、日志打印、文件操作
    scrapy(一):基础用法
    # scrapy(二):get请求
    scrapy(三):post请求
  • 原文地址:https://www.cnblogs.com/1pha/p/7801217.html
Copyright © 2020-2023  润新知