当前位置: 代码迷 >> 综合 >> 【Educational Codeforces Round 16】Codeforces 710A King Moves
  详细解决方案

【Educational Codeforces Round 16】Codeforces 710A King Moves

热度:16   发布时间:2024-01-13 11:45:17.0

The only king stands on the standard chess board. You are given his
position in format “cd”, where c is the column from ‘a’ to ‘h’ and d
is the row from ‘1’ to ‘8’. Find the number of moves permitted for the
king.

Check the king’s moves here
https://en.wikipedia.org/wiki/King_(chess). King moves from the
position e4 Input

The only line contains the king’s position in the format “cd”, where
‘c’ is the column from ‘a’ to ‘h’ and ‘d’ is the row from ‘1’ to ‘8’.
Output

Print the only integer x — the number of moves permitted for the king.

打表。

#include<cstdio>
#include<cstring>
int main()
{int i,j,k,x,y,z;char c;x=getchar()-'a'+1;y=getchar()-'0';if ((x==1||x==8)&&(y==1||y==8))printf("3\n");else{if (x==1||x==8||y==1||y==8)printf("5\n");elseprintf("8\n");}
}
  相关解决方案