⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8hau.c

📁 Many C samples. It is a good sample for students to learn C language.
💻 C
字号:
/* Bai toan tam hoang hau */
#include <stdio.h>

int dong[8], cot[8], cheoxuoi[15], cheonguoc[15];

void print ()
{
  int i;
  printf("\n");
  for (i=0; i<8; i++)
    printf("%3d", dong[i]);
}

void thu(int i)
{
  int j;
  for (j=0; j<8; j++)
  {
    if (cot[j] == 1 && cheoxuoi[i+j] ==1 && cheonguoc[i-j+7] == 1)
    {
      dong[i] = j;
      cot[j] = 0;
      cheoxuoi[i+j] = 0;
      cheonguoc[i-j+7] = 0;
      if (i<7)
        thu(i+1);
      else
        print();
      cot[j] = 1;
      cheoxuoi[i+j] = 1;
      cheonguoc[i-j+7] = 1;
    }
  }
}

void tim()
{
   int i, q;

   for (i=0; i<8; i++)
   {
     cot[i] = 1;
     dong[i] = -1;
   }
   for (i=0; i<15; i++)
   {
     cheoxuoi[i] = 1;
     cheonguoc[i] = 1;
   }
   thu(0);
}

void main()
{
  tim();
  getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -