[Unrated] Gnome Sequencing - 4589
성능 요약
메모리: 17556 KB, 시간: 196 ms
분류
구현
문제 설명
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, being of different physical heights, vary their arrangements to confuse the goblins. Therefore, the goblins must actually measure the beards in centimeters to see if everyone is lined up in order.
Your task is to write a program to assist the goblins in determining whether or not the gnomes are lined up properly, either from shortest to longest beard or from longest to shortest.
입력
The input starts with line containing a single integer N, 0 < N < 30, which is the number of groups to process. Following this are N lines, each containing three distinct positive integers less than 100.
출력
There is a title line, then one line per set of beard lengths. See the sample output for capitalization and punctuation.
답 : 최단 수염부터 가장 긴 수염까지 또는 가장 긴 수염부터 최단 수염까지,
제대로 정렬되었는지를 결정하기 위해 고블린을 돕는 프로그램을 작성하는 것이다.
수염의 길이를 입력받고 if문으로 최단부터 가장 긴 순서대로 정렬되어있는지,
가장 긴수염부터 최단 수염까지 정렬되어 있는지 판단하여 출력한다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); // 그룹의 수
// 제목 출력
System.out.println("Gnomes:");
// 각 그룹에 대해
for (int i = 1; i <= N; i++) {
int[] beards = new int[3]; // 수염 길이 저장할 배열
for (int j = 0; j < 3; j++) {
beards[j] = sc.nextInt(); // 수염 길이 입력 받기
}
// 수염 길이가 최단부터 가장 긴 순서대로 정렬되어 있는 경우
if ((beards[0] < beards[1] && beards[1] < beards[2]) || (beards[0] > beards[1] && beards[1] > beards[2])) {
System.out.println("Ordered");
}
// 수염 길이가 제대로 정렬되어 있지 않은 경우
else {
System.out.println("Unordered");
}
}
sc.close();
}
}
'algorithm > 백준' 카테고리의 다른 글
[백준] 11021. A+B - 7 Java[자바] (0) | 2023.04.01 |
---|---|
[백준] 큰 수 (BIG) - 14928 Java[자바] (0) | 2023.03.31 |
[백준] Hurra! - 26767 Java[자바] (0) | 2023.03.28 |
[백준] SASA 모형을 만들어보자 -23825 Java[자바] (0) | 2023.03.27 |
[백준] Dedupe - 5357 Java[자바] (0) | 2023.03.26 |