작성자 : 조재화

힘들다... 열심히 해야지~~
~cpp 
#include<iostream>
using namespace std;
bool search();
int arr[7][7];
int main()
{
	for(int i=0; i<7; i++)
	{
		for(int j=0; j<7; j++)
			arr[i][j] = -1;
	}
	for(int j=1; j<6; j++)
	{
		for(int j=1; j<6; j++)
			arr[i][j] = 0;
	}
	int x = 2;
	int y = 1;
	arr[x][y]=1;
	int count = 2;
	int xx,yy;
	do
	{
		if(arr[x+1][y-1]=0)
		{
			arr[x+1][y-1]=count;
			x=x+1, y=y-1, count++;
		}
		else if(arr[x+1][y-1]=-1)
		{
			if(y=1)
				yy=4,xx=x;
			if(x=3)
				xx=0,yy=y;
			if(arr[xx+1][yy-1]=0)
			{
				arr[xx+1][yy-1] = count;
				x=xx+1, y=yy-1, count++;
			}
			else
			{
				arr[x][y+1] = count;
				y=y+1, count++;
			}
		}
		else
		{
			arr[x][y+1]=count;
			count++;
		}
	}while(search());
	for(i=1; i<6; i++)
	{
		for(j=1; j<6; j++)
		{
			cout<<arr[i][j];
		}
		cout<<endl;
	}

	return 0;
}

bool search()
{
	for(int i=0; i<7;i++)
	{
		for(int j=0; j<7; j++)
		{
			if(arr[i][j] != 0)
				return true;
		}
	}
	return false;
}
 

SeeAlso 조재화

마방진
Retrieved from http://wiki.zeropage.org/wiki.php/마방진/조재화
last modified 2021-02-07 05:29:25