Educational Codeforces Round 16 A
Description
he 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).
![](http://codeforces.com/predownloaded/f6/4a/f64a2413349b842dc9b81c2a996d184014547882.png)
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
题意:求棋子放在不同位置能走几个方向
解法:模拟+讨论边界情况
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; if(s[0]=='a'&&s[1]=='8') { cout<<"3"<<endl; return 0; } else if(s[0]=='h'&&s[1]=='8') { cout<<"3"<<endl; return 0; } else if(s[0]=='a'&&s[1]=='1') { cout<<"3"<<endl; return 0; } else if(s[0]=='h'&&s[1]=='1') { cout<<"3"<<endl; return 0; } else if(s[0]=='a'&&(s[1]>='1'&&s[1]<='7')) { cout<<"5"<<endl; return 0; } else if(s[0]=='h'&&(s[1]>='1'&&s[1]<='7')) { cout<<"5"<<endl; return 0; } else if((s[0]>='b'&&s[0]<='g')&&(s[1]=='8')) { cout<<"5"<<endl; return 0; } else if((s[0]>='b'&&s[0]<='g')&&(s[1]=='1')) { cout<<"5"<<endl; return 0; } else { cout<<"8"<<endl; } return 0; }