-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_Lab02_3.c
56 lines (52 loc) · 965 Bytes
/
2_Lab02_3.c
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
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int board[4][4];
int main()
{
int p1, p2, x, y,i, j;
int win=0, cnt = 0;
scanf("%d", &p1);
if (p1 == 1)
p2 = 2;
else
p2 = 1;
for (i = 1; i <= 9; i++)
{
scanf("%d%d", &x, &y);
if (i % 2 == 1)
board[x][y] = p1;
else
board[x][y] = p2;
for (j = 1; j <= 3; j++)
{
if (board[j][1] == board[j][2] && board[j][2] == board[j][3] && board[j][1] != 0)
{
cnt = 1;
win = board[j][1];
}
if (board[1][j] == board[2][j] && board[2][j] == board[3][j] && board[1][j] != 0)
{
cnt = 1;
win = board[1][j];
}
}
if (board[1][1] == board[2][2] && board[2][2] == board[3][3] && board[1][1] != 0)
{
cnt = 1;
win = board[1][1];
}
if (board[1][3] == board[2][2] && board[2][2] == board[3][1] && board[1][3] != 0)
{
cnt = 1;
win = board[1][3];
}
if (cnt != 0)
{
printf("%d", win);
break;
}
else if (i == 9)
printf("0");
}
return 0;
}