26.1k views
3 votes
Design and implement a recursive program that solves the Non-Attacking Queens problem. That is, write a program to determine all ways in which eight queens can be positioned on an eight-by-eight chessboard so that none of them are in the same row, column, or diagonal as any other queen. There are no other chess pieces on the board. Store your solutions in an array of strings, giving them the format: . . . . q . . . . q . . . . . . . . . q . . . . . . . . . . q . . . q . . . . . . . . . . . . q . . . . . q . . q . . . . . . . Where "." represents a space with no queen and "q" represents a space with a queen (there is a space between each set of adjacent characters). Sort the array, and then print every solution in order, putting a line of whitespace in between them.

User Kta
by
4.6k points

1 Answer

4 votes

Answer:

gg

Step-by-step explanation:

User Biswajit Chopdar
by
4.2k points