您的位置:首页 > 产品设计 > UI/UE

EightQueens in the game of chess

2008-04-27 21:24 197 查看
国际象棋八皇后相容排阵问题:

My code of today

#include <iostream.h>
//八皇后求解
int k=0,result[10]={0};
int main()
{
void search();
void shresult();
search();

return(0);
}

//Show the result
void shresult()
{
for(k=0;k<8;k++) cout<<result[k]<<',';
cout<<"/t OK"<<endl;
}

//Searching the answer for the problem.
void search()
{
int i,j,judge;
for(i=0;i<8;i++)
{
judge=1;
for(j=0;j<k;j++)
{
if(i==result[j]) judge&=0;
if(i==(result[j]-k+j)) judge&=0;
if(i==(result[j]+k-j)) judge&=0;
}
if(judge){result[k]=i;k++;search();}
}
if(!(k<8)) shresult();
k--;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: