C++版

#include <stdio.h>

#define CHECK_ALL
#define N_ANS 3

int ata_map[8][8];

void clear_map()
{
  for (int i = 0; i < 8; i++)
  {
    for (int j = 0; j < 8; j++)
    {
      ata_map[i][j] = 0;
    }
  }
}

const int yyy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int xxx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

bool put_q_yx(int y, int x)
{
  if (ata_map[y][x])
    return true;

  for (int i = 0; i < 8; i++)
  {
    for (int j = 0; j < 8; j++)
    {
      int ypos = y + j * yyy[i];
      int xpos = x + j * xxx[i];
      if (ypos < 0 || ypos >= 8 || xpos < 0 || xpos >= 8)
      {
        break;
      }
      else
      {
        ata_map[ypos][xpos] = 1;
      }
    }
  }
  ata_map[y][x] = 2;
  return false;
}

void print_map()
{
  putchar('\n');
  for (int i = 0; i < 8; i++)
  {
    for (int j = 0; j < 8; j++)
    {
      if (ata_map[i][j] == 2)
      {
        putchar('Q');
      }
      else
      {
        putchar('.');
      }
    }
    putchar('\n');
  }
}

int main()
{
  int ans = 0, cnt = 0;
  int iii[8];
  for (int i = 0; i < 8; i++)
  {
    iii[i] = 0;
  }
  int t = 0;
  for (iii[0] = 0; iii[0] < 8; iii[0]++)
  {
    for (iii[1] = 0; iii[1] < 8; iii[1]++)
    {
      for (iii[2] = 0; iii[2] < 8; iii[2]++)
      {
        for (iii[3] = 0; iii[3] < 8; iii[3]++)
        {
          for (iii[4] = 0; iii[4] < 8; iii[4]++)
          {
            for (iii[5] = 0; iii[5] < 8; iii[5]++)
            {
              for (iii[6] = 0; iii[6] < 8; iii[6]++)
              {
                for (iii[7] = 0; iii[7] < 8; iii[7]++)
                // the main loop.
                {
                  bool is_hit = false;
                  bool flg_cont = false;
                  clear_map();
                  // and build map
                  for (int i = 0; i < 8; i++)
                  {
                    is_hit = put_q_yx(i, iii[i]);
                    if (is_hit)
                    {
                      flg_cont = true;
                      break;
                    }
                  }
                  if (flg_cont)
                    continue;

                  print_map();
#ifndef CHECK_ALL
                  ans++;
                  if (ans >= N_ANS)
                  {
                    return 0;
                  }
#endif
                  clear_map();
                } // end of main loop
              }
            }
          }
        }
      }
    }
  }
  return 0;
}