1065 A+B and C

时间:2023-03-09 05:27:29
1065 A+B and C

同样是一题会产生溢出的题,不同的是这个用大数类很麻烦,因为有负数的可能性

不妨利用溢出的特性来解题:两个整数和为负数 或者 两个负数和为正数,那么就溢出了。

#include<bits/stdc++.h>
using namespace std; int main(){
int t;
cin>>t;
for(int i=1;i<=t;i++){
long long a,b,c;
cin>>a>>b>>c;
long long res=a+b;
bool flag;
if(a>0&&b>0&&res<0)flag=true; //第一种溢出
else if(a<0&&b<0&&res>=0)flag=false; //第二种溢出
//没溢出
else if(res>c)flag=true;
else flag=false;
cout<<"Case #"<<i<<": "<<(flag?"true":"false")<<endl;
}
return 0;
}