PAT 1065

题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1065

注意溢出规律, 若a>0, b>0, a+b溢出,则 a+b<=0; 若a<0, b<0, a+b溢出,则 a+b>=0.

 1 #include<iostream>
 2 #include<string>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 int main(){
 7     int T; cin>>T;
 8     for(int i=0; i<T; ++i){
 9         long long a, b, c;
10         cin>>a>>b>>c;
11         cout<<"Case #"<<i+1<<": ";
12         bool flag;
13         long long temp =a+b;
14         if(a>0 && b>0 && temp<=0)
15             flag=true;
16         else if(a<0 && b <0 && temp >= 0)
17             flag=false;
18         else
19             flag = (temp > c);
20         if(flag)
21             cout<<"true"<<endl;
22         else
23             cout<<"false"<<endl;
24     }
25 }
原文地址:https://www.cnblogs.com/bochen-sam/p/3402734.html