int board[8][8] = {0}, r =0, c=0, count =0; board[0][0] = 1; NC: c++; if(c==8){ goto PRINT; } r =-1; NR: r++; if(r==8) goto BT; for(int i=0; iif(board[r][i] == 1) goto NR; } for(int i=1; (r-i)>=0 && (c-i)>=0; i++){//Up-diagonal test if(board[r-i][c-i] == 1) goto NR; } for(int i =1; (r+i)<=8 && (c-i)>=0; i++){//Down-diagonal test if(board[r+i][c-i] == 1) goto NR; else{ board[r][c] =1; goto NC; } } BT: c--; if(c == -1) return 0; r=0; while(board[r][c] != 1){//Search the column until a queen is found r++; board[r][c] = 1;//Once a queen is found, take it away and continue the search goto NR;//Stay in the column and look for more options } PRINT: // void print(int board[][8]){ // static cout<< "Solution #"<< count++<< ":"<< endl; for(int i =0;i<8; i++){ for(int j =0; j<8; j++){ cout<< board[i][j]; } cout<< endl; } goto BT; // } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)