King Moves
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 水题: 给出一个点求周围有几个点 AC代码:
1 # include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 char ch1, ch2; 6 scanf("%c%c", &ch1, &ch2); 7 if(ch1 == ‘a‘ && ch2 == ‘1‘) 8 printf("3\n"); 9 else if(ch1 == ‘a‘ && ch2 == ‘8‘) 10 printf("3\n"); 11 else if(ch1 == ‘h‘ && ch2 == ‘1‘) 12 printf("3\n"); 13 else if(ch1 == ‘h‘ && ch2 == ‘8‘) 14 printf("3\n"); 15 else if(ch1 == ‘a‘ || ch1 == ‘h‘ || ch2 == ‘1‘|| ch2 == ‘8‘) 16 printf("5\n"); 17 else 18 printf("8\n"); 19 return 0; 20 }
时间: 2024-10-27 06:02:49