~cpp
#include <iostream>
using namespace std;
int array[20][20] = {0,};
bool exam(int r, int c);
void output();
bool count();
int main()
{
for (int r = 7; r <= 14; r++)
{
for (int c = 7; c <= 14; c++)
{
array[r][c] = 1;
for (int i = 7; i <= 14; i++)
{
for (int j = 7; j <= 14; j++)
{
if (exam(i, j))
array[i][j] = 1;
}
}
if (count())
{
output();
return 0;
}
else
{
for (int a = 0; a <= 19; a++)
for (int b = 0; b <= 19; b++)
array[a][b] = 0;
}
}
}
output();
return 0;
}
bool exam(int r, int c)
{
for (int i = 0; i <= 7; i++)
{
if (array[i+7][c] == 1 || array[r][i+7] == 1 || array[r+i][c+i] == 1 || array[r-i][c-i] == 1 || array[r-i][c+i] == 1 || array[r+i][c-i] == 1)
return false;
}
return true;
}
void output()
{
for (int i = 0; i <= 7; i++)
{
for (int j = 0; j <= 7; j++)
{
cout << array[i+7][j+7] << " ";
}
cout << "\n";
}
}
bool count()
{
int counter = 0;
for (int i = 7; i <= 14; i++)
{
for (int j = 7; j <= 14; j++)
{
if (array[i][j] == 1)
counter++;
}
}
if (counter == 8)
return true;
else
return false;
}
- 지금 보니 무시무시한 소스다... 5중 루프... -_-;; --창섭