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 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
Meaning of the questions:
Analyzing a + b is greater than c, the output Case #X: true, no output Case #X: false;
Input:
Test sample number
abc
...
Output:
Case # 1: false (or to true)
...
Ideas:
(1) a, b, c in the range [-2 63 is , 2 63 is ), it is determined which type of data type long long;
(2) a + b to be noted that the critical situation, if a> 0, b> 0, a + b <= 0, the overflow of the positive (refer to principles of computer Organization), output Case #X: true; if a <0, b <0, a + b> = 0, is negative overflow, the output Case #X: false ;
(3) () in the long long type a + b and c direct comparison to be wrong if statement, it is needed to store a + b temp.
Code:
#include <cstdio>
int main(){
long long a,b,c,temp;
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++){
scanf("%lld %lld %lld",&a,&b,&c);
temp=a+b;
if(a>0&&b>0&&temp<=0){
printf("Case #%d: true\n",i);
}else if(a<0&&b<0&&temp>=0){
printf("Case #%d: false\n",i);
}else if(temp>c){
printf("Case #%d: true\n",i);
}else if(temp<=c){
printf("Case #%d: false\n",i);
}
}
return 0;
}
vocabulary:
… …