LINUX C++ 8 QUEEN

cube.cpp  :

#include <iostream>//
using namespace std ;

int col[8], Left[15], Right[15] ;
int queen[8] ;
int n = 0 ;
int sum = 0 ;

void generate ( )
{
int h,I;
for ( h=0; h<=7; h++ )
{
if ( col[h]&& Left[n+h] && Right[n-h+7] )
{
queen[n] = h ;
col[h] = false ;
Left[n+h] = false ;
Right[n-h+7] = false ;
n += 1 ;
if( n == 8 )
{
sum++ ;
cout << ” ” << sum ;
for( int i = 0; i <= 7; i++ )
cout << “\t” << queen[i] ;
cout << endl ;
}
else generate ( ) ;
n– ;
Left[n+h] = true ;
Right[n-h+7] = true ;
col[h] = true ;
}
}
}

int main ( )
{
cout << “” ;
int c, s ;
for ( c = 0; c <= 7; ++c )
col[c] = true ;
for ( s=0; s <= 14; ++s )
{
Left[s] = true ;
Right[s] = true ;
}
cout << ” arraw number:\t0\t1\t2\t3\t4\t5\t6\t7″ << endl ;
generate ( ) ;
cout << ” 8 queen restult all number. ” << sum << endl ;
return 0;
}

 

Makefile  :

CC = gcc

CFLAGS = -g

INCLUDE = -I. -I/usr/include/ -I/usr/include/X11/ -I/usr/local/include/GL -I/usr/local/src/glut-3.6/include/

LDFLAGS = -L. -L/usr/lib -L/usr/lib/X11 -L/usr/local/lib

LDLIBS = -lglut -lGL -lGLU -lpthread -lm

SRCS = \
cube.cpp

OBJS = \
cube.o

.c.o:
$(CC) $(DEFS) $(INCLUDE) $(CFLAGS) -c $<

all: cubes

cubes: $(OBJS)
$(CC) $(CFLAGS) $(INCLUDE) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@

clean:
rm -f *.o core cubes

 

[gemege@gemege nqueen]$ su
Password:
[root@gemege nqueen]# make
g++ -c -o cube.o cube.cpp
cube.cpp:42:10: warning: missing terminating ” character
cube.cpp:42: error: missing terminating ” character
cube.cpp: In function ‘int main()’:
cube.cpp:43: error: expected primary-expression before ‘int’
cube.cpp:43: error: expected ‘;’ before ‘int’
cube.cpp:44: error: ‘c’ was not declared in this scope
cube.cpp:46: error: ‘s’ was not declared in this scope
make: *** [cube.o] Error 1
[root@gemege nqueen]# make
g++ -c -o cube.o cube.cpp
cube.cpp:42:10: warning: missing terminating ” character
cube.cpp:42: error: missing terminating ” character
cube.cpp: In function ‘int main()’:
cube.cpp:43: error: expected primary-expression before ‘int’
cube.cpp:43: error: expected ‘;’ before ‘int’
make: *** [cube.o] Error 1
[root@gemege nqueen]# make
g++ -c -o cube.o cube.cpp
cube.cpp:42:10: warning: missing terminating ” character
cube.cpp:42: error: missing terminating ” character
cube.cpp: In function ‘int main()’:
cube.cpp:43: error: expected primary-expression before ‘int’
cube.cpp:43: error: expected ‘;’ before ‘int’
cube.cpp:44: error: ‘c’ was not declared in this scope
cube.cpp:46: error: ‘s’ was not declared in this scope
make: *** [cube.o] Error 1
[root@gemege nqueen]# make
g++ -c -o cube.o cube.cpp
gcc -g -I. -I/usr/include/ -I/usr/include/X11/ -I/usr/local/include/GL -I/usr/local/src/glut-3.6/include/ cube.o -L. -L/usr/lib -L/usr/lib/X11 -L/usr/local/lib -lglut -lGL -lGLU -lpthread -lm -o cubes
[root@gemege nqueen]# ./cubes
arraw number: 0 1 2 3 4 5 6 7
1 0 4 7 5 2 6 1 3
2 0 5 7 2 6 3 1 4
3 0 6 3 5 7 1 4 2
4 0 6 4 7 1 3 5 2
5 1 3 5 7 2 0 6 4
6 1 4 6 0 2 7 5 3
7 1 4 6 3 0 7 5 2
8 1 5 0 6 3 7 2 4
9 1 5 7 2 0 3 6 4
10 1 6 2 5 7 4 0 3
11 1 6 4 7 0 3 5 2
12 1 7 5 0 2 4 6 3
13 2 0 6 4 7 1 3 5
14 2 4 1 7 0 6 3 5
15 2 4 1 7 5 3 6 0
16 2 4 6 0 3 1 7 5
17 2 4 7 3 0 6 1 5
18 2 5 1 4 7 0 6 3
19 2 5 1 6 0 3 7 4
20 2 5 1 6 4 0 7 3
21 2 5 3 0 7 4 6 1
22 2 5 3 1 7 4 6 0
23 2 5 7 0 3 6 4 1
24 2 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