⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pku2243.cpp

📁 这是ACM 方面的资料 是PKU的 北京大学的出来的
💻 CPP
字号:
#include <stdio.h>

int test(char *s)
{
	if (s[0] == 'a' && s[1] == '1')
	{
		return 1;
	}
	if (s[0] == 'a' && s[1] == '8')
	{
		return 1;
	}
	if (s[0] == 'h' && s[1] == '1')
	{
		return 1;
	}
	if (s[0] == 'h' && s[1] == '8')
	{
		return 1;
	}
	return 0;
}

int main()
{
	int way[8][8]=
		{
			{ 0, 3, 2, 3 ,2, 3, 4, 5 },
			{ 3, 2, 1, 2, 3, 4, 3, 4 },
			{ 2, 1, 4, 3, 2, 3, 4, 5 },
			{ 3, 2, 3, 2, 3, 4, 3, 4 },
			{ 2, 3, 2, 3, 4, 3, 4, 5 },
			{ 3, 4, 3, 4, 3, 4, 5, 4 },
			{ 4, 3, 4, 3, 4, 5, 4, 5 },
			{ 5, 4, 5, 4, 5, 4, 5, 6 },					
		};
	char s1[3],s2[3];
	int i, j, r_way;
	
	while( scanf("%s %s",s1,s2) != -1 )
	{
		i=s1[0]-s2[0];
		j=s1[1]-s2[1];


		i=(i>=0)?i:(-i);
		j=(j>=0)?j:(-j);
		
		r_way = way[i][j];

		if (i == 1 && j == 1)
		{
			if (test(s1) == 1 || test(s2) == 1)
			{
				r_way = 4;
			}
		}

		printf("To get from %s to %s takes %d knight moves.\n",s1,s2,r_way);
			
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -