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

JollyJumpers/오승균: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair batch-0002 pages from live compare)
 
Line 4: Line 4:
  const int size = 65535;
  const int size = 65535;
  void check_possible (int max);                // Jolly판단 자체가 가능한 수열인가 검사
  void check_possible (int max);                // Jolly판단 자체가 가능한 수열인가 검사
  void check_Jolly (int max, int ar[]);        // Jolly여부를 판단
  void check_Jolly (int max, int ar[]);        // Jolly여부를 판단
  void show_num (int max, int ar[]);            // 입력한 숫자 출력
  void show_num (int max, int ar[]);            // 입력한 숫자 출력
  int main()
  int main()
  {
  {
  int array[size];
  int array[size];
  int num;
  int num;
  int total_num = 0;
  int total_num = 0;
Line 31: Line 31:
  continue;
  continue;
  }
  }
  array[i] = num;
  array[i] = num;
  i++;
  i++;
  system("cls");
  system("cls");
Line 57: Line 57:
  }
  }
   
   
  void check_Jolly (int max, int ar[])
  void check_Jolly (int max, int ar[])
  {
  {
  int temp;
  int temp;
Line 65: Line 65:
  for (int j = 0; j < max - 1; j++)
  for (int j = 0; j < max - 1; j++)
  {
  {
  temp = ar[j] - ar[j + 1] ;
  temp = ar[j] - ar[j + 1] ;
  if (temp < 0)
  if (temp < 0)
  temp = -temp;
  temp = -temp;
Line 80: Line 80:
  }
  }
   
   
  void show_num (int max, int ar[])
  void show_num (int max, int ar[])
  {
  {
  cout << "<Numbers Inputed>" << endl;
  cout << "<Numbers Inputed>" << endl;
  for (int i = 0; i < max - 1; i++)
  for (int i = 0; i < max - 1; i++)
  cout << ar[i] << " ";
  cout << ar[i] << " ";
  cout << endl;
  cout << endl;
  }
  }
Line 91: Line 91:
일단은 오랜만에 프로그램을 열심히 짜서 괜히(?) 뿌듯하네요. 뭐 문제점이나 개선점이 있으면 과감히 -_-;;; 지적해주세요.
일단은 오랜만에 프로그램을 열심히 짜서 괜히(?) 뿌듯하네요. 뭐 문제점이나 개선점이 있으면 과감히 -_-;;; 지적해주세요.
문제에 주어진 스펙에 최대한 맞춰서 프로그램을 짜주세요. -- 보창
문제에 주어진 스펙에 최대한 맞춰서 프로그램을 짜주세요. -- 보창

Latest revision as of 00:16, 27 March 2026

Jolly Jumpers

#include <iostream>
using namespace std;
const int size = 65535;
void check_possible (int max);                // Jolly판단 자체가 가능한 수열인가 검사
void check_Jolly (int max, int ar[]);         // Jolly여부를 판단
void show_num (int max, int ar[]);            // 입력한 숫자 출력
int main()
{
	int array[size];
	int num;
	int total_num = 0;
	int i = 0;

	cout << "숫자를 입력하세요 (종료 : q) : ";

	while (cin >> num)
	{
		if (i == 0 && num > 3000)             // 첫번째 수가 3000이 넘는지 검사
		{
			system("cls");
		    cout << "첫번째 숫자는 3000을 넘어서는 안됩니다." 
				 << "숫자를 입력하세요 (종료 : q) : ";
			continue;
		}
		if (num <= 0)                         // 0이하의 정수가 입력되었는지 검사
		{	
			system("cls");
		    cout << "1이상의 정수를 입력하셔야 합니다." 
				 << "숫자를 입력하세요 (종료 : q) : ";
			continue;
		}
		array[i] = num;
		i++;
		system("cls");
		show_num (i + 1, array);
		cout << "숫자를 입력하세요 (종료 : q) : ";
	}
	system("cls");

	total_num = i + 1;

	check_possible (total_num);
	show_num (total_num, array);
	check_Jolly( total_num, array);

	return 0;
}

void check_possible (int max)
{
	if (max <= 1)
	{	
		cout << "입력된 숫자가 없습니다. 프로그램을 종료합니다." << endl;
		exit(0);
	}
}

void check_Jolly (int max, int ar[])
{	
	int temp;
	
	for (int i = 1; i < max - 1; i++)
	{	
		for (int j = 0; j < max - 1; j++)
		{
			temp = ar[j] - ar[j + 1] ;
			if (temp < 0)
				temp = -temp;
			if (temp == i)
				break;
		}
		if (temp != i)
		{
			cout << "*** Not Jolly ***" << endl;
			exit(0);
		}
	}
	cout << "*** Jolly ***" << endl;
}

void show_num (int max, int ar[])
{
	cout << "<Numbers Inputed>" << endl;
	for (int i = 0; i < max - 1; i++)
		cout << ar[i] << " ";
	cout << endl;
}

Thread

일단은 오랜만에 프로그램을 열심히 짜서 괜히(?) 뿌듯하네요. 뭐 문제점이나 개선점이 있으면 과감히 -_-;;; 지적해주세요. 문제에 주어진 스펙에 최대한 맞춰서 프로그램을 짜주세요. -- 보창