forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
67 lines (53 loc) · 1.13 KB
/
A.cpp
File metadata and controls
67 lines (53 loc) · 1.13 KB
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
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <map>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
string mat[4];
bool check(char ch, int x, int y, int dx, int dy) {
REP(i,4) {
if (mat[x][y] != ch && mat[x][y] != 'T') return false;
x += dx;
y += dy;
}
return true;
}
bool isok(char ch) {
REP(i,4) {
if (check(ch, i, 0, 0, 1)) return true;
}
REP(j,4) {
if (check(ch, 0, j, 1, 0)) return true;
}
if (check(ch, 0, 0, 1, 1)) return true;
if (check(ch, 3, 0, -1, 1)) return true;
return false;
}
void run() {
REP(i,4) cin >> mat[i];
if (isok('X')) {
cout << "X won" << endl;
return;
}
if (isok('O')) {
cout << "O won" << endl;
return;
}
REP(i,4) REP(j,4) if (mat[i][j] == '.') {
cout << "Game has not completed" << endl;
return;
}
cout << "Draw" << endl;
}
int main() {
int k;
cin >> k;
FOR(c,1,k) {
cout << "Case #" << c << ": ";
run();
}
return 0;
}