Saturday, May 30, 2009

[PC]A Multiplication Game

간만에 solve했네요.
참조테이블을 이용하면 효율적입니다.^^

http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110505&format=html

문제요약
1부터 시작하여 2~9까지 임의의 수를 곱하는 것을 반복한다. 두명(stan, ollie)이 진행하는데 첫 순서는 stan이다. 특정 입력값보다 큰거나 같은 값을 부르는 사람이 승리한다.

#include <iostream>
#include <math.h>

typedef unsigned int UInt32;
typedef unsigned long long UInt64;

static const char* WINNER[2] = {"Stan wins.", "Ollie wins."};

int main()
{
	UInt32 input = 0;
	while(std::cin >> input)
	{
		for(int i=1; i<=10; ++i)
		{
			UInt64 stan = 9*pow((long double)18, i-1);
			UInt64 ollie = pow((long double)18, i);

			if(input <= stan)
			{
				std::cout << WINNER[0] << std::endl;
				break;
			}
			if(input <= ollie)
			{
				std::cout << WINNER[1] << std::endl;
				break;
			}
		}
	}
	return 0;
}

No comments:

Post a Comment