-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_Lab07_2.c
77 lines (63 loc) · 1.31 KB
/
2_Lab07_2.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
int map[3][3];
int func(int x);
int main() {
int num;
scanf("%d", &num);
int x, y;
int value;
int ans = 0;
int check = 0;
// numÀÌ 1À̸é OÇ¥½Ã, 2À̸é XÇ¥½Ã
for (int i = 0; i < 9; i++) {
if (i % 2 == 0)
value = num;
else {
if (num == 2)
value = 1;
else
value = 2;
}
scanf("%d %d", &x, &y);
x--, y--;
map[x][y] = value;
if (!check) {
ans = func(value);
if (ans != 0)
check = 1;
}
}
printf("%d\n", ans);
return 0;
}
int func(int x) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (map[i][j] != x)
break;
if (j == 2)
return x;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (map[j][i] != x)
break;
if (j == 2)
return x;
}
}
for (int i = 0; i < 3; i++) {
if (map[i][i] != x)
break;
if (i == 2)
return x;
}
for (int i = 0; i < 3; i++) {
if (map[i][2 - i] != x)
break;
if (i == 2)
return x;
}
return 0;
}