注解
1、简单枚举,从0到两数之和(a),看是否有符合条件的数,有就输出。
2、注意取绝对值。
代码
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cin>>n;
for(int i=0; i<n; i++) {
int a, b;
cin>>a>>b;
int flag = 0;
for(int j=0; j<=a; j++) {
int another = a-j;
if(abs(another-j)==b) {
flag = 1;
cout<<max(another, j)<<" "<<min(another, j)<<endl;
break;
}
}
if(!flag) {
cout<<"impossible"<<endl;
}
}
return 0;
}