소스 ¶
~cpp
#include <iostream>
using namespace std;
#define TRUE 1
#define FALSE 0
int GetYPoint(int x)
{
return (3 * x * x) - (8 * x) + 6;
}
void GetMayaPoint(int& x, int& y, int remainNumber)
{
const int PLUS_X[6] = {-1, +0, +1, +1, +0, -1};
const int PLUS_Y[6] = {+0, -1, -1, +0, +1, +1};
int circleNumber = --y;
bool isAddOne = FALSE;
for (register int i = 0; i < 6; ++i)
{
for (register int j = 0; j < circleNumber; ++j)
{
--remainNumber;
if (0 > remainNumber)
return;
if (4 == i && FALSE == isAddOne)
{
--j;
isAddOne = TRUE;
}
x += PLUS_X[i];
y += PLUS_Y[i];
}
}
}
void main()
{
int willyNumber;
while(1)
{
cout << "0을 입력하면 종료됩니다. 윌리의 숫자를 입력하세요.\n>>";
cin >> willyNumber;
if (0 == willyNumber)
break;
int x = 0;
int y = 1;
for ( ; GetYPoint(y) <= willyNumber; ++y);
--y;
GetMayaPoint(x, y, willyNumber - GetYPoint(y));
cout << "(" << x << ", " << y << ")" << endl;
}
}