Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

BeeMaja/조현태: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair batch-0001 pages from live compare)
 
Line 20: Line 20:
  void GetMayaPoint(int& x, int& y, int remainNumber)
  void GetMayaPoint(int& x, int& y, int remainNumber)
  {
  {
  const int PLUS_X[6] = {-1, +0, +1, +1, +0, -1};
  const int PLUS_X[6] = {-1, +0, +1, +1, +0, -1};
  const int PLUS_Y[6] = {+0, -1, -1, +0, +1, +1};
  const int PLUS_Y[6] = {+0, -1, -1, +0, +1, +1};
  int circleNumber = --y;
  int circleNumber = --y;
  bool isAddOne = FALSE;
  bool isAddOne = FALSE;
Line 36: Line 36:
  isAddOne = TRUE;
  isAddOne = TRUE;
  }
  }
  x += PLUS_X[i];
  x += PLUS_X[i];
  y += PLUS_Y[i];
  y += PLUS_Y[i];
  }
  }
  }
  }

Latest revision as of 23:56, 26 March 2026

BeeMaja/조현태

=== 설명 및 느낀점 ===
위키짜기전에.. 아침운동 삼아 간단히..
그냥 고등학교때 문제 푸는 방식과 동일하다. 그러므로 특별한 설명이 필요 없을듯..
=== 소스 ===
#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;
	}
}

BeeMaja