-
Notifications
You must be signed in to change notification settings - Fork 1
/
12335.cpp
56 lines (50 loc) · 1.2 KB
/
12335.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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool win(vector<string>& v, char c) {
for (int i=0; i<4; i++) {
for (int j=0; j<4; j++) {
if (v[i][j] != c && v[i][j] != 'T') break;
if (j == 3) return true;
}
for (int j=0; j<4; j++) {
if (v[j][i] != c && v[j][i] != 'T') break;
if (j == 3) return true;
}
}
for (int i=0; i<4; i++) {
if (v[i][i] != c && v[i][i] != 'T') break;
if (i == 3) return true;
}
for (int i=0; i<4; i++) {
if (v[i][3-i] != c && v[i][3-i] != 'T') break;
if (i == 3) return true;
}
return false;
}
bool draw(vector<string>& v) {
for (int i=0; i<4; i++) {
for (int j=0; j<4; j++) {
if (v[i][j] == '.') return false;
}
}
return true;
}
void solve(int idx) {
vector<string> v(4);
for (int i=0; i<4; i++) cin >> v[i];
cout << "Case #" << idx << ": ";
if (win(v, 'X')) cout << "X won";
else if (win(v, 'O')) cout << "O won";
else if (draw(v)) cout << "Draw";
else cout << "Game has not completed";
cout << "\n";
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t; cin >> t;
for (int i=1; i<=t; i++) solve(i);
return 0;
}