A. King Moves

来源:互联网 发布:程序员健康问题 编辑:程序博客网 时间:2024/05/17 22:42

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Example
input
e4
output
8

解题说明:此题根据输入的国王位置判断国王的走法,注意区分四个角,四条边以及其他位置,只有这三种可能。


#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main (){char a;int b,c=8;scanf("%c%d",&a,&b);if(((a=='a')||(a=='h'))&&((b==1)||(b==8))){c=3;}else if((a=='a')||(a=='h')||(b==1)||(b==8)){c=5;}printf("%d\n",c);return 0;}


0 0
原创粉丝点击