U E D R , A S I H C RSS

Jolly Jumpers/문보창

소감

2005/02/19 Accepted 0:00.014 64
한개의 정수 1 n 이 들어와 있을경우 이것을 Jolly로 판단해야할까?

코드

~cpp 
// no10038 - Jolly Jumpers
#include <iostream>  
using namespace std; 

const int MAX = 3000;

bool isJolly(int n); 
inline void showJolly(bool w) { w ? cout << "Jolly\n" : cout << "Not jolly\n"; } 
inline void eatline() { while(cin.get() != '\n') continue; }; 

int main()   
{  
	int n;                                      // 뒤에 이어지는 정수들의 개수 
	 while (cin >> n) 
	{ 
		if (n == 1) 
			showJolly(true);	    // n이 1일 경우 Jully 이다. 왜 그럴까?           
 		else     
			isJolly(n) ? showJolly(true) : showJolly(false); 
		eatline();
	} 
	return 0; 
} 

bool isJolly(int n) 
{ 
	bool bitJolly[MAX];		           // bitJolly[0]은 사용하지 않는다. 
	int i; 
	for (i=1; i<n; i++) 
		bitJolly[i] = 0; 
	int ftemp, ltemp;                         // 앞숫자, 뒷숫자 
	 cin >> ftemp; 
	int gap; 
	for (i=1; i<n; i++) 
	{ 
		cin >> ltemp; 
		gap = abs(ftemp-ltemp); 
		if (0 < gap && gap < n) 
		{ 
			bitJolly[gap] = 1; 
			ftemp = ltemp; 
		} 
		else 
			return false; 
	} 
	for (i=1; i<n; i++)
	{
		if (!bitJolly[i])                  
			return false; 
	}
	return true; 
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:34
Processing time 0.0173 sec