?? pku2243.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 + -