#include <iostream>
#include <iomanip>
using namespace std;
int board[8][8];
int chk(int c, int r)
{
for(int i = 0; i < c; ++i)
{
// Проверка горизонтали
if(board[i][r]) return 0;
// Проверка диагонали
if (r-c+i>=0) if (board[i][r-c+i]) return 0;
if (r+c-i< 8) if (board[i][r+c-i]) return 0;
}
return 1;
}
int vert(int i) // Установка i-й вертикали
{
if (i == 8) return 1;
for(int j = 0; j < 8; ++j)
if (chk(i,j))
{
board[i][j] = 1;
if (vert(i+1)) return 1;
board[i][j] = 0;
}
return 0;
}
int main(int argc, char * argv[])
{
vert(0);
for(int i = 0; i< 8; ++i)
{
for(int j = 0; j< 8; ++j)
cout << (board[i][j] ? '#' : '.');
cout << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgYm9hcmRbOF1bOF07CgppbnQgY2hrKGludCBjLCBpbnQgcikKewogICAgZm9yKGludCBpID0gMDsgaSA8IGM7ICsraSkKICAgIHsKICAgICAgICAvLyDQn9GA0L7QstC10YDQutCwINCz0L7RgNC40LfQvtC90YLQsNC70LgKICAgICAgICBpZihib2FyZFtpXVtyXSkgcmV0dXJuIDA7CiAgICAgICAgLy8g0J/RgNC+0LLQtdGA0LrQsCDQtNC40LDQs9C+0L3QsNC70LgKICAgICAgICBpZiAoci1jK2k+PTApIGlmIChib2FyZFtpXVtyLWMraV0pIHJldHVybiAwOwogICAgICAgIGlmIChyK2MtaTwgOCkgaWYgKGJvYXJkW2ldW3IrYy1pXSkgcmV0dXJuIDA7CiAgICB9CiAgICByZXR1cm4gMTsKfQoKaW50IHZlcnQoaW50IGkpIC8vINCj0YHRgtCw0L3QvtCy0LrQsCBpLdC5INCy0LXRgNGC0LjQutCw0LvQuAp7CiAgICBpZiAoaSA9PSA4KSByZXR1cm4gMTsKICAgIGZvcihpbnQgaiA9IDA7IGogPCA4OyArK2opCiAgICAgICAgaWYgKGNoayhpLGopKQogICAgICAgIHsKICAgICAgICAgICAgYm9hcmRbaV1bal0gPSAxOwogICAgICAgICAgICBpZiAodmVydChpKzEpKSByZXR1cm4gMTsKICAgICAgICAgICAgYm9hcmRbaV1bal0gPSAwOwogICAgICAgIH0KICAgIHJldHVybiAwOwp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqIGFyZ3ZbXSkKewogICAgdmVydCgwKTsKICAgIGZvcihpbnQgaSA9IDA7IGk8IDg7ICsraSkKICAgIHsKICAgICAgICBmb3IoaW50IGogPSAwOyBqPCA4OyArK2opCiAgICAgICAgICAgIGNvdXQgPDwgKGJvYXJkW2ldW2pdID8gJyMnIDogJy4nKTsKICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICB9Cn0K