标签:
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).
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‘.
Print the only integer x — the number of moves permitted for the king.
e4
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 }
标签:
原文地址:http://www.cnblogs.com/lyf-acm/p/5798152.html