-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8queens_goto.cpp
More file actions
69 lines (42 loc) · 803 Bytes
/
8queens_goto.cpp
File metadata and controls
69 lines (42 loc) · 803 Bytes
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
#include <iostream>
#include <cmath>
using namespace std;
//CS211 ASSIGNMENT 5
//8 Queens 1-D Array with GOTO
int main() {
int q[8];
int c = 0;
int counter=0;
q[0] = 0;
NC:
c++;
if (c==8) goto PRINT;
q[c] = -1;
NR:
q[c]++;
if (q[c] == 8) goto BACKTRACK;
TEST:
for(int i=0; i<c; i++) {
if ((q[i] == q[c]) || (c-i == abs(q[c] - q[i]))) {
goto NR;
}
}
goto NC;
BACKTRACK:
c--;
if (c == -1) return 0;
goto NR;
PRINT:
counter++;
cout << "answer "<< counter <<endl<<endl;
for( int i = 0 ; i < 8 ; i++ ) {
for ( int j = 0 ; j < 8 ; j++ ) {
if (q[i] == j) cout << "Q";
else cout<< "x" ;
}
cout<<endl;
}
cout<<endl;
goto BACKTRACK;
return 0;
}