1011. A+B and C

Given three integers A, B and C in the interval [-231, 231], please determine whether A+B is greater than C.
Input format:
The first line of input gives a positive integer T (<=10), which is the number of test cases. Then T groups of test cases are given, each group occupies one 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" in one line if A+B>C, otherwise output "Case #X: false", where X is the number of the test case (starting from 1).
Input example:
4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647
Output example:
Case #1: false
Case #2: true
Case #3: true
Case #4: false
Note: It seems very simple The question, but I still struggled for a long time where I went wrong, and I was foolishly blinded by the test example of the question. The title is INT_MAX+0, so your own test instance can pass, but if it is INT_MAX+INT_MAX, it will overflow! So be sure to use double to define. Attached at the bottom is the code for how to test various types of ranges.

#include<stdio.h>
int main()
{
    int T, i;
    double A[10], B[10], C[10];
    scanf("%d", &T);
    for (i=0; i<T; i++)
        scanf("%lf%lf%lf", &A[i], &B[i], &C[i]);
    for (i=0; i<T; i++){
        if (A[i]+B[i]>C[i]) printf("Case #%d: true\n", i+1);
        else printf("Case #%d: false\n", i+1);
    }
    return 0;
}

The range of the integer length

#include <stdio.h>
#include <limits.h>
int main()
{
    printf("The value of INT_MAX is %i\n", INT_MAX);
    printf("The value of INT_MIN is %i\n", INT_MIN);
    printf("An int takes %d bytes\n", sizeof(int));
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326424100&siteId=291194637