Hi! Since I've been waiting for a response to my previous post and no one has yet replied, I tried coding your sample problem. This is my first encounter with that n-Queen problem. It took me 2 long hrs to realize it, and I've done it with a compiler. Should I be worried? Waaaaaaahhh...do you think I'll have a shot? Tomorrow is my exam
#include<iostream.h>
#include<stdio.h>
main()
{
int n, x, y, count=0;
cout<<"n: ";
cin>>n;
for(y=0;y<n;y++)
{
for(x=0;x<n;x++)
{
if((y+count)==x)
cout<<"|Q_";
else
cout<<"|__";
}
cout<<"\n";
count++;
if((y==n/2)&&(n%2==1)) //for odd values of n
count=-1*count+1;
if((y==n/2-1)&&(n%2==0)) //for even values of n
count=-1*count+1;
}
return 0;
}
I just realized, this isn't going to work with if n<5....crap..im screwed![]()










Reply With Quote











