题意及思路

题意:给出三个64位的的整数,求a+b是否大于c。

思路:正常来说,long long 数据范围正好合适。只是计算比较的时候,需要考虑溢出的问题(正溢出或负溢出)。见下图:



注意点:


代码

#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int t;
    cin >> t;
    long long a,b,c,rs; 
    for(int i=1;i<=t;i++){
        scanf("%lld %lld %lld",&a,&b,&c);
        bool f;
        rs = a+b;
        if(a>0&&b>0&&rs<0) f = true; //正溢出 rs<0
        else if(a<0&&b<0&&rs>=0) f = false; //负溢出 rs>=0
        else if(rs>c) f = true; //无溢出
        else f = false;
        cout << "Case #" << i <<": ";
        if(f) cout << "true" << endl;
        else cout << "false" << endl;
    }
    return 0;
}