|
|
1.1 root 1: int up[15], down[15], rows[8], x[8];
2: int queens(), print();
3:
4: main()
5: {
6: int i;
7:
8: for (i = 0; i < 15; i++)
9: up[i] = down[i] = 1;
10: for (i = 0; i < 8; i++)
11: rows[i] = 1;
12: queens(0);
13: return 0;
14: }
15:
16: queens(c)
17: {
18: int r;
19:
20: for (r = 0; r < 8; r++)
21: if (rows[r] && up[r-c+7] && down[r+c]) {
22: rows[r] = up[r-c+7] = down[r+c] = 0;
23: x[c] = r;
24: if (c == 7)
25: print();
26: else
27: queens(c + 1);
28: rows[r] = up[r-c+7] = down[r+c] = 1;
29: }
30: }
31:
32: print()
33: {
34: int k;
35:
36: for (k = 0; k < 8; k++)
37: printf("%c ", x[k]+'1');
38: printf("\n");
39: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.