~cpp 
#include <iostream>
#include <vector>
using namespace std;

void main()
{
	int size;
	cout << "몇 행(열)을 만드시겠습니까 ? =";
	cin >> size;

	vector <vector <int> > array;

	array.resize(size);

	for (int i = 0 ; i < size ; i++)
	{
		array[i].resize(size);
	}

	int st_place_h = 0;
	int st_place_y = size/2;
	int max = size * size;

	for (int t = 0 ; t < size ; t++)
	{
		for (int y = 0 ; y < size ; y++)
			array[t][y] = 0;
	}


	array[st_place_h][st_place_y] = 1;


	for (int k = 1 ; k <= max ; k++)
	{
		array[st_place_h][st_place_y] = k;
		st_place_h--;
		st_place_y++;
		if (st_place_h < 0)
			st_place_h = size-1;
		if (st_place_y == size)
			st_place_y = 0;
		if (array[st_place_h][st_place_y] != 0)
		{
			st_place_h ++;
			if (st_place_h >= size)
				st_place_h = 0;
			st_place_h ++;
			st_place_y --;
			if (st_place_y <0 )
				st_place_y = size-1;
		}
		if (st_place_h >= size)
			st_place_h = 0;

	}

	for (int arr=0 ; arr < size ; arr++)
	{
		for (int arr_=0 ; arr_<size ; arr_++)
			cout << array[arr][arr_] << "\t";
	cout << endl;
	}


}



Retrieved from http://wiki.zeropage.org/wiki.php/마방진/장창재
last modified 2021-02-07 05:29:24