For this program, I have to determine if the given configuration has exactly one queen in each row and one in each column. If it does, the program outputs "Yes" and if not, it outputs "No". I have everything correct except for i need to fix the nested for loop towards the bottom. Just can't figure out how to make it execute correctly. Thanks!
"Enter the rows containing queens, in order by column: "
Does that mean that one element in 'board' is one column on the board and the value in that element tells on which row of that column the Queen is?
If so, there is exactly one Queen on each column. What remains to be checked is whether two or more Queens are on the same row.
For example:
1 2 3 4 5 6 7
bool unique = true;
for ( int pivot=0; pivot < 7; ++pivot ) {
IF any of board[pivot+1 .. 7] has same value as board[pivot]
THEN unique = false, break
}
if ( unique ) ...
I think you're trying to use a 1D array to simulate a 2D config of queens, which is fine, but wouldn't you want the indices of the array to be the rows?
From here you can realize you don't need a nested loop at this stage and need only see if all the input is unique from 0 to 7. I'd also like to point out that you're solving an 8 Rooks problem, not an 8 Queens problem.