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

来源:互联网 发布:知乎 苏德战争 编辑:程序博客网 时间:2024/06/06 00:23

一开始用大数运算···就像某网友说的:已哭晕在厕所···

根据题中要求:

①考虑到溢出 

A>0&&B>0 而A+B<=0 或 A<0&&B<0 而A+B>=0 这两种情况即为 溢出 容易判断 前者必定大于未溢出的C而后者必定小于未溢出的C

②未溢出的 直接用用long long 进行判断

#include<iostream>#include<cstring>#include<map>#include<string>#include<cmath>#include<algorithm>using namespace std;int main(){    int T;    long long A, B, C, Sum;    cin>>T;    for(int i=1; i<=T; i++)    {        bool ans;        cin>>A>>B>>C;        Sum=A+B;        if(A>0&&B>0&&Sum<=0)            ans=true;        else            if(A<0&&B<0&&Sum>=0)                ans=false;        else        {            ans=(Sum>C ? true:false);        }        cout<<"Case #"<<i<<": "<<(ans ? "true" : "false")<<endl;    }    return 0;}


0 0
原创粉丝点击