Problems 1065 A + B and (64bit) (20point (s)) C Easy only once * complement fixed point of the machine

The basic idea:

The title suggests, note that the data size and a long long int, int four bytes, long long8 bytes, so that a plus or minus 2 ^ 31, 2 ^ 63 plus or minus a range to be noted;

 

key point:

The last test on the cards in the negative spillover judgment. The problem complement, 64-bit two's complement negative minimum 10000 0000 ...., i.e. -2 ^ 63, the two add up to 0000 ... 0000, the two negative overflow comprising adding 0;

 

 1 #include<iostream>
 2 #include<stdlib.h>
 3 #include<stdio.h>
 4 #include<vector> 
 5 #include<string>
 6 #include<math.h>
 7 #include<algorithm>
 8 using namespace std;
 9 using std::vector; 
10 typedef long long ll;
11 int main() {
12     ll a, b, c;
13     int n;
14     scanf("%d", &n);
15     for (int i = 0; i < n; i++) {
16         scanf("%lld %lld %lld", &a, &b, &c);
17         ll d = a + b;
18         //cout << "reasult:" << d << endl;
19         if (a > 0 && b > 0) {
20             if (d < 0)
21                 printf("Case #%d: true\n", i + 1);
22             else if (d > c) {
23                 printf("Case #%d: true\n", i + 1);
24             }
25             else {
26                 printf("Case #%d: false\n", i + 1);
27             }
28         }
29         else if (a < 0 && b < 0) {
30             if (d >= 0)
31                 printf("Case #%d: false\n", i + 1);
32             else if (d > c) {
33                 printf("Case #%d: true\n", i + 1);
34             }
35             else {
36                 printf("Case #%d: false\n", i + 1);
37             }
38         }
39         else {
40             if (d > c) {
41                 printf("Case #%d: true\n", i + 1);
42             }
43             else {
44                 printf("Case #%d: false\n", i + 1);
45             }
46         }
47     }
48     system("pause");
49     return 0;
50 }

Guess you like

Origin www.cnblogs.com/songlinxuan/p/12187619.html