## 题目

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:

 ``````1 2 3 4 `````` ``````3 1 2 3 2 3 4 9223372036854775807 -9223372036854775808 0 ``````

### Sample Output:

 ``````1 2 3 `````` ``````Case #1: false Case #2: true Case #3: false ``````

## 代码

 `````` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 `````` ``````#include #include using namespace std; long long a,b,c; int n; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld%lld%lld",&a,&b,&c); long long ans=a+b; if(a>0&&b>0&&ans<0) { printf("Case #%d: true\n",i); continue; } if(a<0&&b<0&&ans>=0) { printf("Case #%d: false\n",i); continue; } if(ans>c) printf("Case #%d: true\n",i); else printf("Case #%d: false\n",i); } return 0; } ``````

## 思路

1. 当A+B>=263时，显然有A+B>C，A+B会因超过long long的正向最大值而发生正溢出，由于题目给定的A和B最大均为263-1，故A+B最大为264-2，因此long long存储正溢出后的值的区间为[-263, -2]，由(264-2)%(264)=-2可得右边界，所以当A>0 && B>0 && A+B<0 时，输出true。
2. 当A+B<-263时，显然有A+B<C成立，但是A+B会因超过long long 的负向最小值而发生负溢出。由于题目给定的A和B的最小值为-263，故A+B最小为-264，因此使用long long 存储负溢出后的值的区间为[0, 263)。所以当 A<0 && B<0 &&="" a+b="">=0时为负溢出，输出false。

 ``````1 `````` ``````a + b >= 0 ; ``````

 ``````1 2 `````` ``````ans = a + b ; ans >= 0 ; ``````

update：和编译器有关，第一种写法G++过不了，换CLANG++成功。

codeblock在debug中遇到进程无法退出可以用