-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcc.c
More file actions
74 lines (72 loc) · 1.56 KB
/
Copy pathcc.c
File metadata and controls
74 lines (72 loc) · 1.56 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
68
69
70
71
72
73
74
#include<stdio.h>
int display(int chess2[16]) {
int chessplate[4][4];
int i2 = 0, j2 = 0;
while (i2 < 4) {
j2 = 0;
while (j2 < 4) {
chessplate[i2][j2] = chess2[i2 * 4 + j2];
j2 = j2 + 1;
}
i2 = i2 + 1;
}
i2 = 0;
j2 = 0;
while (i2 < 4) {
j2 = 0;
while (j2 < 4) {
if (chessplate[i2][j2] == 1) printf("%d\n",j2);
j2 = j2 + 1;
}
i2 = i2 + 1;
}
return 0;
}
int PutQueen(int chess[16], int a[4], int b[7], int c[7], int n, int sum) {
int col, i, j;
col = 0;
while (col < 4) {
if (a[col] && b[n + col] && c[n - col + 3]) {
chess[n * 4 + col] = 1;
a[col] = 0;
b[n + col] = 0;
c[n - col + 3] = 0;
if (n == 3) {
sum = sum + 1;
display(chess);
} else
sum = PutQueen(chess, a, b, c, n + 1, sum);
chess[n * 4 + col] = 0;
b[n + col] = 1;
c[n - col + 3] = 1;
a[col] = 1;
}
col = col + 1;
}
return sum;
}
int main() {
int chess1[16];
int a1[4], b1[7], c1[7];
int sum1 = 0;
int i1;
i1 = 0;
while (i1 < 16) {
chess1[i1] = 0;
i1 = i1 + 1;
}
i1 = 0;
while (i1 < 4) {
a1[i1] = 1;
i1 = i1 + 1;
}
i1 = 0;
while (i1 < 7) {
b1[i1] = 1;
c1[i1] = 1;
i1 = i1 + 1;
}
sum1 = PutQueen(chess1, a1, b1, c1, 0, sum1);
printf("%d\n",sum1);
return 0;
}