A + B Is Overflow
2015-10-16 18:37
369 查看
Description |
Judge whether the sum of A and B will exceed the range of 32-bit signed integer. |
Input |
There are multiple test cases. The first line of each test case is a positive integer T, indicating the number of test cases. For each test case, there is only one line including two 32-bit signed integers A and B. |
Output |
For each test case, output one line. If the sum of A and B will exceed the range of integer, print "Yes", else print "No". |
Sample Input |
3 1 2 -2147483648 2147483647 2147483647 2147483647 |
Sample Output |
No No Yes #include<stdio.h> int main() { int t,a,b; while(~scanf("%d",&t)) { while(t--) { scanf("%d%d",&a,&b); if(a>0&b>0&&a+b<=0||a<0&&b<0&&a+b>=0) { printf("Yes\n"); } else{ printf("No\n"); } } } return 0; |