杭电OJ 1194(C++)

基础题。

#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;
}

继续加油。

发布了138 篇原创文章 · 获赞 1 · 访问量 7017

猜你喜欢

转载自blog.csdn.net/Intelligence1028/article/details/104575092