首页 > 代码库 > codeforces 710A King Moves(水)
codeforces 710A King Moves(水)
output
standard outputThe 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).
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 else14 cout << 5 << endl;15 }16 else if(str[0] == ‘h‘)17 {18 if(str[1] == ‘8‘ || str[1] == ‘1‘)19 cout << 3 << endl;20 else21 cout << 5 << endl;22 }23 else if(str[1] == ‘8‘ || str[1] == ‘1‘)24 {25 cout << 5 << endl;26 }27 else28 cout << 8 << endl;29 return 0;30 }
codeforces 710A King Moves(水)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。