topic content
Given 3 integers A, B, and C in the interval [−231,231], determine whether A+B is greater than C.
Input format:
Input line 1 gives a positive integer T (≤10), the number of test cases. Then T groups of test cases are given, each on a line, and A, B, and C are given in order. Integers are separated by spaces.
Output format:
For each set of test cases, output Case #X: true
if A+B>C in one line, else output Case #X: false
, where X
is the test case number (starting from 1).
Input sample:
4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647
no blank line at the end
Sample output:
Case #1: false
Case #2: true
Case #3: true
Case #4: false
no blank line at the end
Problem solving ideas
Nothing to say, use long to record data and compare the size
Detailed code
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
cin.tie(); //减少cin读入数据时的时间损耗
int n;
long long int a=0,b=0,c=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>a>>b>>c;
if(a+b>c){
cout<<"Case #"<<i+1<<": true"<<endl;
}
else{
cout<<"Case #"<<i+1<<": false"<<"\n";
}
}
}