1065 A+B and C (64bit) (20)(大数相加、正溢出、负溢出)

正溢出:两个正数相加超过了该数据类型能表示的最大范围,结果为负数

负溢出:两个负数相加超过了该数据类型能表示的最小范围,结果为正数包括零

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = 0x3f3f3f3f;
typedef long long ll;
int main() {
    int t,k=0;
    ll a,b,c,sum;
    cin >>t;
    while(t--) {
        k++;
        cin >> a >> b >> c;
        sum = a + b;
        cout << "Case #" << k <<": " ;
        if(a > 0 && b > 0 && sum < 0) cout << "true" << endl;//如果A+B超过了longlong 那么一定大于C
        else if(a < 0 && b < 0 && sum >=0) cout << "false" << endl;//如果A+B超过了longlong最小值 那么一定小于C
        else if(sum > c) cout << "true" << endl;
        else  cout << "false" << endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/LLLAIH/p/11689505.html
今日推荐