-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1197_Lonesome_Knight.cpp
81 lines (76 loc) · 2.11 KB
/
1197_Lonesome_Knight.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Author: Sohel Rana
* Date: 2021-12-17 12:15:32
* Task: 1197_Lonesome_Knight
**/
#include <bits/stdc++.h>
#define endl '\n'
#define sqr(x) (x) * (x)
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x/gcd(x,y)) * y)
#define pf(x) push_front(x)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)x.size()
#define make_unique(x) (x).resize(unique(all((x)))-(x).begin())
#define debug(x) cerr<<#x<<" = "<<(x)<< endl
#define debug2(x,y) cerr<<#x<<" = "<<(x)<<","<<#y<<" = "<<(y)<< endl
#define unsyncIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
using ll = long long;
using db = double;
using ld = long double;
using ull = unsigned long long;
const ld PI = acos((ld)-1);
const int MOD = 1e9+7;
const long long INF = 1e18;
const ld EPS = 1.0e-14;
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
//unsyncIO
int t;
cin >> t;
while (t--) {
int cnt = 0;
string s;
cin >> s;
int r, c, tr, tc;
r = s[0] - 'a' + 1;
c = s[1] - '0';
r--, c--;
tr = r, tc = c;
//up left
tr -= 2, tc--;
if ((tr >= 0 and tr <= 7) and (tc >= 0 and tc <= 7)) cnt++;
//up right
tc = c + 1;
if ((tr >= 0 and tr <= 7) and (tc >= 0 and tc <= 7)) cnt++;
//left up
tr = r, tc = c;
tr--, tc -= 2;
if ((tr >= 0 and tr <= 7) and (tc >= 0 and tc <= 7)) cnt++;
//left down
tr = r + 1;
if ((tr >= 0 and tr <= 7) and (tc >= 0 and tc <= 7)) cnt++;
tr = r, tc = c;
//right up
tr--, tc += 2;
if ((tr >= 0 and tr <= 7) and (tc >= 0 and tc <= 7)) cnt++;
//Right down
tr = r + 1;
if ((tr >= 0 and tr <= 7) and (tc >= 0 and tc <= 7)) cnt++;
//down left
tr = r, tc = c;
tr += 2, tc--;
if ((tr >= 0 and tr <= 7) and (tc >= 0 and tc <= 7)) cnt++;
//down right
tc = c + 1;
if ((tr >= 0 and tr <= 7) and (tc >= 0 and tc <= 7)) cnt++;
cout << cnt << endl;
}
return 0;
}