-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1331.cpp
55 lines (42 loc) · 937 Bytes
/
P1331.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
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int check[8][8] = {};
int main() {
cin.tie(NULL);
cout.tie(NULL);
int px = 0, py = 0;
int nx = 0, ny = 0;
int sx = 0, sy = 0;
string s;
cin >> s;
sx = px = s[0] - 'A';
sy = py = s[1] - '1';
int flag = 0;
for (int i = 1; i <= 36; i++) {
if(i == 36) {
nx = sx;
ny = sy;
} else {
cin >> s;
nx = s[0] - 'A';
ny = s[1] - '1';
}
if (check[nx][ny]) {
flag = 1;
break;
}
if ((abs(nx - px) == 1 && abs(ny - py) == 2) || (abs(nx - px) == 2 && abs(ny - py) == 1)) {
px = nx;
py = ny;
check[nx][ny] = 1;
continue;
}
flag = 1;
break;
}
if(flag) cout << "Invalid";
else cout << "Valid";
return 0;
}