1065 A+B and C (64bit) (20 分)
阿新 • • 發佈:2018-11-08
1065 A+B and C (64bit) (20 分)
程式碼
c++版
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, sum;
int n;
cin>>n;
for (int i = 0; i < n; i++) {
cin>>a>>b>>c;
sum = a+b;
if (a>0 && b>0 && sum<=0) {//兩個很大的正數相加溢位為負
cout<<"Case #"<<i+1<<": true"<<endl;
} else if (a<0 && b<0 && sum>=0) {//兩個很小的數溢位為正
cout<<"Case #"<<i+1<<": false"<<endl;
} else if (sum > c) {
cout<<"Case #"<<i+1<<": true"<<endl;
} else {
cout<<"Case #"<<i+1<<": false"<<endl;
}
}
return 0;
}
java版
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
BigInteger a, b, c;
int n = scan.nextInt ();
for (int i = 0; i < n; i++) {
a = scan.nextBigInteger();
b = scan.nextBigInteger();
c = scan.nextBigInteger();
if (a.add(b).compareTo(c) == 1) {
System.out.println("Case #"+(i+1)+": true");
} else {
System.out.println("Case #"+(i+1)+": false");
}
}
}
}