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
Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[42];
scanf("%s", s);
int x, y;
if (s[0] == 'a' || s[0] == 'h') {
x = 2;
} else {
x = 3;
}
if (s[1] == '1' || s[1] == '8') {
y = 2;
} else {
y = 3;
}
printf("%d\n", x * y - 1);
return 0;
}
Related posts:
Increase Sequence
Practice
Zuma
Oh Sweet Beaverette
Wrong Answer on Test 233 (Easy Version)
Kuroni and the Gifts
Coffee Varieties (hard version)
Nested Rubber Bands
15 Puzzle Game: Existence Of The Solution
New Year and Forgotten Tree
Cards
Một số vấn đề đáng chú ý trong môn Tin học - Phan Công Minh
New Year and Old Property
PolandBall and Gifts
Replicating Processes
Game on Tree
Beautiful IP Addresses
Number of Ways
Ehab and Path-etic MEXs
Paint it really, really dark gray
Competitive Programmer
Rin and The Unknown Flower
Interesting Subarray
New Year and Finding Roots
Parity Game
Solve RMQ (Range Minimum Query) by finding LCA (Lowest Common Ancestor)
Casinos and travel
The Values You Can Make
Security
Palisection
Binomial Coefficients
Largest Submatrix 3