美文网首页PAT
B1065 A+B and C (64bit) (大数溢出)

B1065 A+B and C (64bit) (大数溢出)

作者: Tsukinousag | 来源:发表于2020-01-27 19:34 被阅读0次

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

    1.如果a>0,b>0,a+b溢出结果得到的却是个负值或0.

    1. 如果是负数相加向下溢出,得到的是正值或0

    2. 最后一种情况,就是不溢出,直接判断是否满足a+b>c。

    //这题难受在我又用大数大法做了,但最后一个测试点过不去,考试的时候二十分的题代码量必然不会大,要注意!!!!

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <string.h>
    #include <cmath>
    #include <math.h>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    #include <stack>
    #define lowbit(i)((i)&(-i))
    using namespace std;
    typedef long long ll;
    const int MAX=21;
    const int INF=0x3f3f3f3f;
    const int MOD=1000000007;
    const int SQR=633;
    int main(){
        int N;
        ll a,b,c;
        while(cin>>N){
            for(int i=0;i<N;i++){
                bool equal = false;         
                cin>>a>>b>>c;
                long long add = a+b;
                if(a>0&&b>0&&add<=0) equal = true;
                else if(a<0&&b<0&&add>=0) equal = false;
                else if(add>c) equal = true;
                cout<<"Case #"<<i+1<<": ";
                cout<<(equal?"true":"false")<<endl;
            }
        }
        return 0;
    } 
    

    相关文章

      网友评论

        本文标题:B1065 A+B and C (64bit) (大数溢出)

        本文链接:https://www.haomeiwen.com/subject/gesethtx.html