#include <iostream>
using namespace std;
char chessboard[100][100] ={' '};
int n;
int savingposition[100][2]={ };
//checking rows....
bool checking (int row, int column){
for(int i = 0; i< n; i++){
for(int j = 0; j < n; j++) {
if((j+i== column+row|| column - row == j-i || i== row || j == column) && chessboard[i][j]=='Q')
return false;
}}
return true;
}
void displaytable()
{
for(int i = 0; i< n; i++){
for(int j = 0; j < n; j++) {
if (chessboard[i][j] != 'Q')
cout << '-';
else
cout << chessboard[i][j];
}
cout << endl;
}
for(int i = 0; i< n; i++){
for(int j = 0; j < 2; j++) {
//cout << savingposition[i][j];
}
cout << endl;
}
}
int main()
{
cout << "how many queens? enter from 1 to 1000-->";
cin >>n;
for(int row = 0; row < n; row++)
{
for(int column = 0; column <n; column++){
if( checking (row,column)){
chessboard[row][column] = 'Q';
savingposition[row][0] = row;
savingposition[row][1] = column; break;
if(row < n)
row = row+1;
column = 0;
}
else if(chessboard[row][column] != 'Q' && column == n ){
row = row-1;
column = savingposition[row][1];
chessboard[row][column] = '-';
if(column < n)
column = column+1;
}
}
displaytable();
}
return 0;
}
mimah1 0 Newbie Poster
neithan 1 Junior Poster in Training
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
mimah1 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
mimah1 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
mimah1 0 Newbie Poster
neithan 1 Junior Poster in Training
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
mimah1 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.