U E D R , A S I H C RSS

Bee Maja/허준수

== 소감 ==
생각을 코드로 옮기는 것은 어렵다.
결국 코드는 길어지고... -..ㅡ;;

소스파일

~cpp
#include <iostream>
using namespace std;

int x, y;
void firstStep(int count, int &start, int input)
{
	for(; count>0; count--){
		x--;
		y++;
		if(start == input) break;
		start++;
	}
}

void secondStep(int count, int &start, int input)
{
	for(; count>0; count--){
		x--;
		if(start == input) break;
		start++;
	}	
}

void thirdStep(int count, int &start, int input)
{
	for(; count>0; count--){
		y--;
		if(start == input) break;
		start++;
	}
}

void firthStep(int count, int &start, int input)
{
	for(; count>0; count--){
		x++;
		y--;
		if(start == input) break;
		start++;
	}
}

void fifthStep(int count, int &start, int input)
{
	for(; count>0; count--){
		x++;
		if(start == input) break;
		start++;
	}
}

void sixthStep(int count, int &start, int input)
{
	for(; count>0; count--){
		y++;
		if(start == input) break;
		start++;
	}
}

void process(int input)
{
	int count = 0;
	for(count; count<100000; count++)
	{
		if((3*(count*count + count) + 1) >= input)
			break;
	}

	x = count;
	y = 0;
	int start = (3*(count*count + count)+1) - 6*count + 1;
	
	int index = (input-start)/count + 1;
	
	for(int i = 1; i<=index; i++)
	{
		switch(i)
		{
		case 1:
			firstStep(count,start,input);
			break;
		case 2:
			secondStep(count,start,input);
			break;
		case 3:
			thirdStep(count,start,input);
			break;
		case 4:
			firthStep(count,start,input);
			break;
		case 5:
			fifthStep(count,start,input);
			break;
		case 6:
			sixthStep(count,start,input);
			break;
		}
	}

	cout << x << " " << y << endl;
}

int main()
{
	int input;
	while(cin >>input) {
	process(input);
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:36
Processing time 0.0072 sec