본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 4589 : Gnome Sequencing

반응형

https://www.acmicpc.net/problem/4589

 

4589번: Gnome Sequencing

In the book All Creatures of Mythology, gnomes are kind, bearded creatures, while goblins tend to be bossy and simple-minded. The goblins like to harass the gnomes by making them line up in groups of three, ordered by the length of their beards. The gnomes

www.acmicpc.net

간단한 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

t를 선언한 후 3개의 수염정보를 입력받을 vector를 선언 후 입력습니다

📔 정답출력

인접한 고블린의 수염길이 차이들을 곱했을 때 결과가 양수라면 오름차순 혹은 내림차순이므로 이경우에는 Ordered를 아닌 경우엔 Unordered를 출력해줍니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
	cin >> t;
	cout << "Gnomes:\n";
	while(t--){
		vector <int> beard(3);
		for(int i = 0; i < 3; i++) cin >> beard[i];
		if((beard[1] - beard[0]) * (beard[2] - beard[1]) > 0) cout << "Ordered\n";
		else cout << "Unordered\n";
	}
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.