Untitled

 avatar
user_7169643
plain_text
2 years ago
1.4 kB
1
Indexable
Never
#include<iostream>
using namespace std;
const int SIZE = 16;

void Solve(int data[], int which);
bool Checker(int data[], int which);
void Output(int data[]);

int main()
{
	int data[SIZE] = { 0 };
	Solve(data, 0);
	return 0;
}

void Solve(int data[], int which)
{
	for(int i = 1; i <= SIZE; i++)
{
	data[which] = i;
	if (Checker(data, which))
	{
		if (which == SIZE - 1)
		{
			Output(data);
		}
		else
	{
		Solve(data, which + 1);
	}
}
}
}

bool Checker(int data[], int which)
{
if (which == 3 && data[0] + data[1] + data[2] + data[3] != 34)return false;
if (which == 7 && data[4] + data[5] + data[6] + data[7] != 34)return false;
if (which == 11 && data[8] + data[9] + data[10] + data[11] != 34)return false;
if (which == 15 && data[12] + data[13] + data[14] + data[15] != 34)return false;

if (which == 15 && data[0] + data[5] + data[10] + data[15] != 34)return false;
if (which == 15 && data[3] + data[6] + data[9] + data[12] != 34)return false;

if (data[0] == 3 && data[15] && data[1] == data[14] && data[2] == data[13] && data[3] == data[12]
&& data[4] == data[11] && data[5] == data[10] && data[6] == data[9] && data[7] == data[8])
{
return false;
}
return true;
}

void Output(int data[])
{
for (int i = 0; i < SIZE; i++)
{
cout << data[i] << "";
if ((i + 1) % 4 == 0) cout << endl;
}
 cout << endl;
}