码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForce 710A King Moves

时间:2016-08-23 10:11:12      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

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 }
View Code

 



CodeForce 710A King Moves

标签:

原文地址:http://www.cnblogs.com/lyf-acm/p/5798152.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!