codeforces710A--King Moves水

来源:互联网 发布:统计软件 编辑:程序博客网 时间:2024/05/21 15:04
D - King Moves
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 710A
Appoint description: 

Description

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.

Sample Input

Input
e4
Output

8

可以走多少步(周围有多少格)

12345678910111213141516171819202122232425262728293031
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){char s[3];while(~scanf("%s",&s)){ if(s[1]=='8'||s[1]=='1') { if(s[0]=='a'||s[0]=='h') printf("3\n"); else printf("5\n"); } else if(s[0]=='a'||s[0]=='h') { if(s[1]=='1'||s[1]=='8') printf("3\n"); else printf("5\n"); } else printf("8\n"); }} 


0 0