-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12759.cpp
99 lines (97 loc) · 1.17 KB
/
12759.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 12759. 틱! 택! 토!
// 2019.08.22
// 구현
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int map[4][4];
bool check(int checkNum)
{
for (int i = 1; i <= 3; i++)
{
int cnt = 0;
for (int j = 1; j <= 3; j++)
{
if (map[i][j] == checkNum)
{
cnt++;
}
}
if (cnt == 3)
{
return true;
}
}
for (int i = 1; i <= 3; i++)
{
int cnt = 0;
for (int j = 1; j <= 3; j++)
{
if (map[j][i] == checkNum)
{
cnt++;
}
}
if (cnt == 3)
{
return true;
}
}
int cnt = 0;
for (int i = 1; i <= 3; i++)
{
if (map[i][i] == checkNum)
{
cnt++;
}
}
if (cnt == 3)
{
return true;
}
cnt = 0;
for (int i = 1; i <= 3; i++)
{
if (map[i][4 - i] == checkNum)
{
cnt++;
}
}
if (cnt == 3)
{
return true;
}
return false;
}
int main()
{
int start;
cin >> start;
int end = (start == 1) ? 2 : 1;
for (int i = 0; i < 9; i++)
{
int x, y;
cin >> x >> y;
if (i % 2 == 0)
{
map[x][y] = start;
}
else
{
map[x][y] = end;
}
if (check(start))
{
cout << start << endl;
return 0;
}
if (check(end))
{
cout << end << endl;
return 0;
}
}
cout << "0" << endl;
return 0;
}