codeforces 710A King Moves(水)

output
standard output

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 dis 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

 

 分析:给你横纵坐标,瞎搞就好。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     char str[3];
 6     ios::sync_with_stdio(false);
 7     cin.tie(0);
 8     cin >> str;
 9     if(str[0] == 'a')
10     {
11         if(str[1] == '8' || str[1] == '1')
12         cout << 3 << endl;
13         else
14         cout << 5 << endl;
15     }
16     else if(str[0] == 'h')
17     {
18         if(str[1] == '8' || str[1] == '1')
19         cout << 3 << endl;
20         else
21             cout << 5 << endl;
22     }
23     else if(str[1] == '8' || str[1] == '1')
24     {
25         cout << 5 << endl;
26     }
27     else
28         cout << 8 << endl;
29     return 0;
30 }

 

转载于:https://www.cnblogs.com/PrayG/p/5809842.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值