PAT Advanced 1065 A+B and C (64bit) (20分)

Given three integers A, B and C in [−], you are supposed to tell whether A+B>C.

Input Specification:

The first line of the input gives the positive number of test cases, T (≤). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.

Output Specification:

For each test case, output in one line Case #X: true if A+B>C, or Case #X: false otherwise, where X is the case number (starting from 1).

Sample Input:

3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0

Sample Output:

Case #1: false
Case #2: true
Case #3: false

大数用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 N=sc.nextInt();
        BigInteger A,B,C;
        for(int i=1;i<=N;i++){
            A=sc.nextBigInteger();
            B=sc.nextBigInteger();
            C=sc.nextBigInteger();
            if(A.add(B).compareTo(C)>0){
                System.out.printf("Case #%d: true\n",i);
            }else{
                System.out.printf("Case #%d: false\n",i);
            }
        }
    }
}

原文地址:https://www.cnblogs.com/littlepage/p/12216124.html

时间: 2024-07-29 15:18:52

PAT Advanced 1065 A+B and C (64bit) (20分)的相关文章

PAT:1065. A+B and C (64bit) (20) AC

#include<stdio.h> #include<stdlib.h> int main() { int n; scanf("%d",&n); for(int i=1 ; i<=n ; ++i) { long long a,b,c; scanf("%lld%lld%lld",&a,&b,&c); long long sum=a+b; //[思维]:判断sum是否正负溢出,溢出的话不能直接按计算判断! i

PAT (Advanced Level) Practice 1011 World Cup Betting (20 分)

With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their

1065 A+B and C (64bit) (20分)(水)

Given three integers A, B and C in [−], you are supposed to tell whether A+B>C. Input Specification: The first line of the input gives the positive number of test cases, T (≤). Then T test cases follow, each consists of a single line containing three

PAT Advanced 1069 The Black Hole of Numbers (20分)

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in

PAT 1065 A+B and C (64bit) (20)

1065. A+B and C (64bit) (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C. Input Specification: The first line of the input gives the po

pat 1116 Come on! Let&#39;s C(20 分)

1116 Come on! Let's C(20 分) "Let's C" is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny as the following: 0

PAT (Advanced Level) 1065. A+B and C (64bit) (20)

因为会溢出,因此判断条件需要转化.变成b>c-a #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<algorithm> using namespace std; long long a,b,c; int main() { int T; scanf("%d",&T);

PAT甲题题解-1065. A+B and C (64bit) (20)-大数溢出

第一眼以为是大数据,想套个大数据模板,后来发现不需要.因为A.B.C的大小为[-2^63, 2^63],用long long 存储他们的值和sum. 接下来就是分类讨论:如果A > 0, B < 0 或者 A < 0, B > 0,sum不会溢出,直接和C判断比较即可.如果A > 0, B > 0,sum可能会溢出, 溢出的话为负数,所以sum < 0时候说明溢出了,那么肯定是大于C的.如果A < 0, B < 0,sum可能会溢出,同理,sum &g

pat(A) 1065. A+B and C (64bit) (java大数)

代码: import java.util.*; import java.math.*; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); int t=cin.nextInt(); for(int i=1;i<=t;i++) { BigInteger a,b,c; a=cin.nextBigInteger(); b=cin.nextBigInteger()