题意:输入a,b,c三个数,问a+b是否大于c。
思路:输入在long long范围内,只要考虑上溢和下溢的情况即可。
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int n;
ll a, b, c;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a >> b >> c;
cout << "Case #" << i << ": ";
ll res = a + b;
bool flag;
if (a>0&&b>0&&res<=0) flag = true;
else if (a<=0&&b<0&&res>=0) flag = false;
else if (res>c) flag = true;
else flag = false;
if (flag) cout << "true" << endl;
else cout << "false" << endl;
}
return 0;
}