U E D R , A S I H C RSS

마방진/장창재

~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;
	}


}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:24
Processing time 0.0069 sec