1065. A+B and C (64bit) (20)

时间:2022-09-01 09:55:50

涨了个知识, LLONG_MAX这种类似的常量是包含再climits这个头文件里的

#include<iostream>
#include<climits>
#pragma warning (disable:4996)
using namespace std;
bool compare(long long int A, long long int B, long long int C)
{
    if (A > 0 && B > 0 && A > LLONG_MAX - B) return true;//判断上溢出
    if (A < 0 && B < 0 && A < LLONG_MIN - B) return false;//判断下溢出
    else return A + B > C;//未出现溢出情况
}
int main()
{
    long long int A, B, C;
    int N;
    cin >> N;
    for (int t = 1;t <= N;t++)
    {

        scanf("%lld %lld %lld", &A, &B, &C);    
        printf("Case #%d: ", t);
        if (compare(A, B, C)) printf("true\n");
        else printf("false\n");
    }
}