PAT (Advanced Level) Practice - 1065 A+B and C (64bit)(20 分)

题目链接:点击打开链接

题目大意:略。

解题思路:一般想到只能搞大数了,但这题有一点小技巧,比最大数都要大的话,return 1;同理,比最小数都小的话,return 0;其他情况就肯定不会超范围,就常规做法。

AC 代码

#include<bits/stdc++.h>
#include<cmath>

#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
#define MOD 1000000007

using namespace std;

typedef long long ll;

ll a,b,c;

int fun()
{
    if(a>0&&b>0 && a>LLONG_MAX-b) return 1;
    if(a<0&&b<0 && a<LLONG_MIN-b) return 0;
    return a+b>c;
}

int main()
{
    int n,kase=1;
    while(~scanf("%d",&n))
    {
        while(n--)
        {
            scanf("%lld%lld%lld",&a,&b,&c);
            printf(fun()?"Case #%d: true\n":"Case #%d: false\n",kase++);
        }
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Dream_Weave/article/details/81585764