Given three integers A, B and C in [−2^ 63,2^63], 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 (≤10). 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
该题没有涉及数据结构和算法,只是简单模拟,做题过程中没有考虑到溢出问题,A和B的范围都在[−2^ 63,2^63],所以A+B会有可能超出long long的范围,所以一定要考虑到溢出。
若A>0,B>0时,A+B<0,说明正溢出,A+B一定大于C,为true; 若A<0,B<0时,A+B>0,说明负溢出,A+B一定小于C,为false;
代码:
#includeint main(){ int t; scanf("%d",&t); for(int i =1;i<=t;i++){ long long a,b,c,ans; scanf("%lld%lld%lld",&a,&b,&c); ans = a+b; if(a>0&&b>0&&ans<0){ printf("Case #%d: truen",i); } else if(a<0&&b<0&&ans>=0){ printf("Case #%d: falsen",i); } else if(ans>c) printf("Case #%d: truen",i); else printf("Case #%d: falsen",i); } return 0; }



