prg15_6g.cpp
来自「数据结构c++语言描述stl版 威廉兄弟的好书,值得看,这是配书代码」· C++ 代码 · 共 41 行
CPP
41 行
// File: prg15_6g.cpp
// the program solves the 8-Queens problem. it prompts the user for
// the starting row for the queen in column 0 and calls the recursive
// backtracking function queens() to determine if there is a solution.
// if there is a solution, the position of the queens is passed to
// the chessboard object, board, and a call to its drawBoard() function
// shows the placement of the queens graphically using the drawing
// package discussed in Chapter 13
#include <iostream>
#include <vector>
// graphical display of 8-Queens solution
#include "d_gqueen.h"
using namespace std;
int main ()
{
int row;
vector<int> queenList(8);
chessBoard board;
// enter a starting row for queen in column 0
cout << "Enter row for queen in column 0: ";
cin >> row;
cout << endl;
// see if there is a solution
if (queens(queenList, row))
{
board.setQueens(queenList);
// display the solution
board.drawBoard();
}
else
cout << "No solution" << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?