PAT Grade A-Analog Type-1065 A+B and C (64bit) Problem Solving Ideas

1065 A+B and C (64bit) (20 分)

Insert picture description here

Ideas

Grasp the details, the range of long long is [− 2 63, 2 63) [-2^{63},2^{63})[263,26 3 ), but the range given in the title is[− 2 63, 2 63] [-2^{63},2^{63}][263,26 3 ], if the test data of the question is used to2 63 2^{63}26 3 is to use the large integer addition algorithm, which is more troublesome, but fortunately there is not.

Therefore, the idea of ​​this question is to use the long long type to discuss the out-of-bounds.

Code

#include <bits/stdc++.h>
using namespace std;

int main()
{
    
    
    int n,i,j;
    long long a,b,c;
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
    
    
        scanf("%lld%lld%lld",&a,&b,&c);  

        long long res  = a+b;
        if (a>0 && b>0 && res <= 0 )
            printf("Case #%d: true\n",i+1);
        else if (a<0 && b<0 && res >= 0 )
            printf("Case #%d: false\n",i+1);
        else if(res > c)
            printf("Case #%d: true\n",i+1);
        else
            printf("Case #%d: false\n",i+1);

    }
}

Guess you like

Origin blog.csdn.net/weixin_43999137/article/details/114004849
Recommended