思路:
将几盘看作二维坐标,始点与终点距离用xDistance yDistance组成,王 后 车 象以不同的的情况考虑。
源码:
#include<stdio.h>
#include<math.h>
int main()
{
//测试数据组数
int nGroup = 0;
scanf("%d",&nGroup);
for(int i = 0; i < nGroup; i++)
{
char begin[5], end[5];
scanf("%s %s", begin, end);
//x , y 方向上的距离
int xDistance, yDistance;
xDistance = abs(begin[0] - end[0]);
yDistance = abs(begin[1] - end[1]);
if(xDistance == 0 && yDistance == 0 )
printf("0 0 0 0\n");
else{
//王
if(xDistance > yDistance)
printf("%d ", xDistance);
else
printf("%d ", yDistance);
//后
if(xDistance == 0 || yDistance == 0 || xDistance == yDistance)
printf("1 ");
else
printf("2 ");
//车
if(xDistance == 0 || yDistance == 0)
printf("1 ");
else
printf("2 ");
//象
if( (yDistance == 0 && xDistance%2 != 0) || (xDistance == 0&&yDistance%2 != 0))
printf("Inf\n");
else if(xDistance == yDistance)
printf("1\n");
else
printf("2\n");
}
}
}