题意:输入2个数 是s,d;
s是x,y的和,d是x,y的差。(x,y只能为正整数或者0)
如果x,y中出现了负数就输出impossible。
要注意的是x=(s+d)/2;y=(s-d)/2;
因为x,y是正整数,所以a==(int)a&&b==(int)b;
#include<iostream>
using namespace std;
int main()
{
int t;
double a,b;
int s,d;
double temp;
cin>>t;
while(t--)
{
cin>>s>>d;
a=(s+d)/2.0;
b=(s-d)/2.0; //2.0 0不能丢!!!!
if(b>=0&a==(int)a&&b==(int)b) ///易错点!!!!!a,b必为整数!!!!
{
if(b>a)
{
temp=b;
b=a;
a=temp;
}
cout<<a<<" ";
cout<<b<<endl;
}
else cout<<"impossible"<<endl;
}
return 0;
}
C++--ACM之杭电OJ--1194 Beat the Spread
猜你喜欢
转载自blog.csdn.net/William_Sunrise/article/details/81295941
今日推荐
周排行