```cpp
#include<iostream>
#include<cmath>
using namespace std;
int x[21];
int n = 8;
int num = 0;
void Print()
{
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
{
if (x[i] == j)
{
cout << "1 ";
}
else
{
cout << "0 ";
}
}
cout << endl;
}
cout << "********************************" << endl;
}
void Hang(int r)
{
if (r == n + 1)
{
Print();
num++;
return;
}
for (int i = 1; i <= n; ++i)
{
bool f = true;
x[r] = i;
for (int j = 1; j < r; ++j)
{
if (x[j] == x[r] || abs(j - r) == abs(x[j] - x[r]))
{
f = false;
break;
}
}
if (f)
{
Hang(r + 1);
}
}
}
int main()
{
Hang(1);
cout << num;
return 0;
}