POJ 1657 Distance on Chessboard G++

 

 

 

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm> //max
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int o=0;o<n;o++)
	{
		string a,b;
		cin>>a>>b;
		int x1,y1;
		x1=a[0]-'a';
		y1=a[1]-'0';
		int x2,y2;
		x2=b[0]-'a';
		y2=b[1]-'0';
		if((x1==x2)&&(y1==y2))
		{
			cout<<0<<" "<<0<<" "<<0<<" "<<0<<endl;
			continue;
		}
		cout<<max(abs(x2-x1),abs(y2-y1))<<" ";//王 
		if(abs(x2-x1)==abs(y2-y1))//后 
		{
			cout<<1<<" ";
		}else if((x1==x2)||(y1==y2))
		{
			cout<<1<<" ";
		}else
		{
			cout<<2<<" ";
		}
		if((x1==x2)||(y1==y2))//车 
		{
			cout<<1<<" ";
		}else
		{
			cout<<2<<" ";
		}		
		if(abs(x2-x1)==abs(y2-y1))//相
		{
			cout<<1<<" "<<endl;
		}else if(((x1+y1)%2)!=((x2+y2)%2))
		{
			cout<<"Inf"<<endl;
		}else
		{
			cout<<2<<" "<<endl;
		}		
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/woniupengpeng/article/details/82979580