您的位置:首页 > 其它

浙大PAT 1065 A+B and C (64bit) (20)

2016-02-28 19:30 465 查看
//题目关键在于对于可能出现溢出的情况的处理

#include<iostream>

#include<fstream>

#include<algorithm>

#include<vector>

#include<stack>

#include<queue>

#include<math.h>

#include<string>

#include <iomanip> 

using namespace std;

//#define fin cin  

int main()  

{  

/*ifstream fin("d:\in.txt" ); 
if (! fin.is_open())  

cout << "Error opening file";
system("pause");
exit (1); 
}*/
 
 
long long a,b,c,MAX=9223372036854775807;
int num;
cin>>num;
for(int i=0;i<num;i++)
{
cin>>a>>b>>c;
if(a>=0&&b>=0)
{
if((a-MAX+b)>0)
{
if(c<=0)
cout<<"Case #"<<i+1<<": "<<"true"<<endl;
else
{
if((a-MAX+b-c+MAX)>0)
cout<<"Case #"<<i+1<<": "<<"true"<<endl;
else
cout<<"Case #"<<i+1<<": "<<"false"<<endl;

}
}
else
{
if((a+b)>c)
cout<<"Case #"<<i+1<<": "<<"true"<<endl;
else
cout<<"Case #"<<i+1<<": "<<"false"<<endl;
}
}
else if(a<=0&&b<=0)
{
if((a+MAX+1+b)<0)
{
 
cout<<"Case #"<<i+1<<": "<<"false"<<endl;
 
}
else
{
if((a+b)>c)
cout<<"Case #"<<i+1<<": "<<"true"<<endl;
else
cout<<"Case #"<<i+1<<": "<<"false"<<endl;
}
}
else
{
long temp;
if(a<0)
{
temp=a;
a=b;
b=temp;
}
long long middle=6223372036854775807;
a=a-middle;
b=b+middle;
if((a+b)>c)
cout<<"Case #"<<i+1<<": "<<"true"<<endl;
else
cout<<"Case #"<<i+1<<": "<<"false"<<endl;

}
}

system("PAUSE");  

    return 0;  

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  浙大PAT