Knight

 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
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
freopen("knight.in", "r", stdin);
freopen("knight.out", "w", stdout);
int n;
cin>>n;
char vert;
int h, v;
int otv[n];
for(int i=0; i<n; i++) {
cin>>vert>>h;
if(vert=='a') v=1;
if(vert=='b') v=2;
if(vert=='c') v=3;
if(vert=='d') v=4;
if(vert=='e') v=5;
if(vert=='f') v=6;
if(vert=='g') v=7;
if(vert=='h') v=8;
if((h==2 && v==2) || (h==7 && v==2) || (h==2 && v==7) || (h==7 && v==7)) otv[i]=4;
else if(h>2 && h<7 && v>2 && v<7) otv[i]=8;
else if((v==1 && h==1) || (v==8 && h==1) || (v==1 && h==8) || (v==8 && h==8)) otv[i]=2;
else if((h<3 || h>6) && (v<3 || v>6)) otv[i]=3;
else if(((h>2 && h<7) && (v==2 || v==7)) || ((h==2 || h==7) && (v>2 && v<7))) otv[i]=6;
else otv[i]=4;
}
for(int i=0; i<n; i++) printf("%d ", otv[i]);
return 0;
}