CSU 1459: Chess

题目:

Input

Output

Sample Input
3
E 2 E 3
F 1 E 8
A 3 A 3
Sample Output
Impossible
2 F 1 B 5 E 8
0 A 3


这个题现在可能有点问题,反正我没AC,网上的代码也都不能AC了

代码:

#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
	int t;
	char ch[10];
	char a, b, c, d;
	scanf("%d", &t);
	gets(ch);
	while (t--)
	{
		gets(ch);
		a = ch[0], b = ch[2], c = ch[4], d = ch[6];
		int xa = a - 'A', xb = b - '1', xc = c - 'A', xd = d - '1';
		if ((xa + xb + xc + xd) % 2)printf("Impossible\n");
		else if (xa == xc&&xb == xd)printf("0 %c %c\n", a, b);
		else if (xa + xb == xc + xd || xa - xb == xc - xd)printf("1 %c %c %c %c\n", a, b, c, d);
		else
		{
			int t = (xc + xd - xa - xb) / 2;
			if (xa + t >= 0 && xa + t <= 7 && xb + t >= 0 && xb + t <= 7)
				printf("2 %c %c %c %c %c %c\n", a, b, xa + t + 'A', xb + t + '1', c, d);
			else printf("2 %c %c %c %c %c %c\n", a, b, xc - t + 'A', xd - t + '1', c, d);
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/nameofcsdn/article/details/80268433