PAT B] [A + B and C

Subject description:

Given interval [-2 31 is 2 31 is ] an integer of 3 A, B and C in, please determines whether A + B is greater than C.

Input formats:

The first input line is given positive integer T (≤10), are the number of test cases. T is then given set of test cases, each per line, the order is given A, B and C. Between integer separated by a space.

Output formats:

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

Sample input:

4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647

Sample output:

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

Problem-solving ideas:

Note range

Code:

#include<iostream>
using namespace std;
int main() {
    int num =0;
    long long A,B,C;
    cin >> num;
    for (int i=0;i< num;i++) {
        cin >> A>>B>>C;
        if (A+B > C) {
            cout << "Case #" <<i+1<< ":" << " true"<< endl;
        }
        else {
            cout << "Case #" <<i+1<< ":" << " false"<< endl;
        }
    }
    return 0;
}
Published 55 original articles · won praise 30 · views 9802

Guess you like

Origin blog.csdn.net/chaifang0620/article/details/105003590
Recommended