CodeForce 710A King Moves

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
");
 9     else if(ch1 == 'a' && ch2 == '8')
10         printf("3
");
11     else if(ch1 == 'h' && ch2 == '1')
12         printf("3
");
13     else if(ch1 == 'h' && ch2 == '8')
14         printf("3
");
15     else if(ch1 == 'a' || ch1 == 'h' || ch2 == '1'|| ch2 == '8')
16         printf("5
");
17     else
18         printf("8
");
19     return 0;
20 }
View Code


生命不息,奋斗不止,这才叫青春,青春就是拥有热情相信未来。
原文地址:https://www.cnblogs.com/lyf-acm/p/5798152.html