PDA

View Full Version : سوال: نیاز به راهنمایی درباره کدهای برنامه n وزیر



veniz2008
شنبه 28 آبان 1390, 12:19 عصر
سلام دوستان،من یک قطعه برنامه درباره مساله n وزیر دارم که البته اجرا نمیشه و بعضی از قسمت هاشو هم متوجه نمیشم،من کد رو میذارم دوستان لطف کنند یه توضیح کامل بگن،

#include<iostream.h>
#include<math.h>
#include<conio.h>

int *col,n;

bool promising(int);

void queens(int i)
{
int j;
if(promising(i))
if (i==n){
for(int index=1;index<=n;index++)
cout<<col[index]<<" ";
cout<<endl;
}
else
for(j=1;j<=n;j++)
{
col[i+1] = j;
queens(i+1) ;
}
}

bool promising(int i)
{
int k;
bool myswitch;
k=1;
myswitch = true;
while (k<i && myswitch)
{
if(col[i]==col[k]||abs(col[i]-col[k])==(i-k))
myswitch = false;
k++;
}
return myswitch;
}

void main()
{
cout<<"Enter Number Of Queens\n";
cin>>n;
col=new int[n];
queens(0);
getch();
}
سوال اولم: int *col یعنی چی؟
سوال دوم : new int[n یعنی چی؟
برنامه موقع اجرا 4 تا خطا میده،لیست خطاها رو میذارم،لطف کنید بگید دلیل این خطاها چیه؟(من سعی کردم که اصلاحشون کنم ولی نتونستم،لطفا کدها رو تصحیح کنید):
Compiling NONAME00.CPP:
Error NONAME00.CPP 7: Declaration syntax error
Error NONAME00.CPP 12: Call to undefined function 'promising' in function queens(int)
Error NONAME00.CPP 26: Variable 'bool' is initialized more than once
Error NONAME00.CPP 26: Declaration syntax error

ممنونم از کمکی که میکنید.