基础题。
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int s, d; //和,差
int a, b; //分数
while (n--)
{
cin >> s >> d;
//和与差之和为奇数,则除以2不是整数
if ((s + d) % 2 == 1)
{
cout << "impossible" << endl;
continue;
}
a = (s + d) / 2;
b = (s - d) / 2;
if (a >= 0 && b >= 0)
cout << max(a, b) << " " << min(a, b) << endl;
else
cout << "impossible" << endl;
}
return 0;
}
继续加油。