Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.
Input Specification:
The first line of the input gives the positive number of test cases, T (<=10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.
Output Specification:
For each test case, output in one line "Case #X: true" if A+B>C, or "Case #X: false" otherwise, where X is the case number (starting from 1).
Sample Input:3 1 2 3 2 3 4 9223372036854775807 -9223372036854775808 0Sample Output:
Case #1: false Case #2: true Case #3: false
题解
#include<cstdio> #include<iostream> using namespace std; int main() { long a, b, c, temp;; int result[10], n; cin >> n; for (int i = 0; i < n; i++) { scanf("%lld%lld%lld", &a, &b, &c); temp = a + b; if (a > 0 && b > 0 && temp < 0) //正溢出 result[i] = 1; else if (a < 0 && b < 0 && temp>=0) //负溢出 result[i] = 0; else if (temp > c) result[i] = 1; else result[i] = 0; } for (int i = 0; i < n; i++) { if (result[i]) cout << "Case #" << i + 1 << ": true" << endl; else cout << "Case #" << i + 1 << ": false" << endl; } return 0; } //此题考的是计算机组成原理部分,两个正数相加为负数即为正溢出 //两个负数相加为正数即为负溢出,另外此题中A和B并没有取到2^63, //否则要用带负数的大整数运算,因为long long最大范围为2^63(开集) //A+B不能直接在if里和C比较,要间接赋给temp再进行比较