달마루
기획자에서 개발자로
달마루
전체 방문자
오늘
어제
  • 분류 전체보기 (334)
    • 기획 이야기 (3)
    • 개발자로 전향한 이유 (1)
    • Github Address (1)
    • 개발자, 그 여정 (11)
      • 기초특강 (4)
      • 국비학원 선정 (4)
      • BitCamp_수업내용 (1)
      • 학원 프로젝트 후기 (1)
      • 정보처리기사 (1)
      • 개발 이야기 (0)
    • 개념 창고 (126)
      • JAVA (50)
      • CS (1)
      • Database (27)
      • NetWork (2)
      • 자료 구조 (2)
      • React (8)
      • Spring (3)
      • JPA (1)
      • HTML & CSS (18)
      • JS (3)
    • algorithm (186)
      • 백준 (161)
      • 프로그래머스 (23)
    • 사는 이야기 (0)

블로그 메뉴

  • Github
  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • Bronze III
  • 백준알고리즘
  • Algorithm
  • java
  • select
  • HTML
  • 혼자공부하는SQL
  • 혼공MySQL
  • java algorithm
  • SQL고득점Kit
  • SQL
  • 자바
  • 알고리즘풀이
  • Bronze IV
  • 알고리즘
  • 혼공SQL
  • react
  • BOJ
  • 백준문제풀이
  • sql 문제풀이
  • Scanner
  • 문제풀이
  • BOJ algorithm
  • math
  • 백준
  • BRONZE
  • 프로그래머스
  • Bronze V
  • programmers
  • MySQL

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
달마루

기획자에서 개발자로

[백준] Gnome Sequencing - 4589 Java[자바]
algorithm/백준

[백준] Gnome Sequencing - 4589 Java[자바]

2023. 3. 29. 23:51


[Unrated] Gnome Sequencing - 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

성능 요약

메모리: 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
    'algorithm/백준' 카테고리의 다른 글
    • [백준] 11021. A+B - 7 Java[자바]
    • [백준] 큰 수 (BIG) - 14928 Java[자바]
    • [백준] Hurra! - 26767 Java[자바]
    • [백준] SASA 모형을 만들어보자 -23825 Java[자바]
    달마루
    달마루
    항상 어제보다 좋은 코드를 지향합니다. https://github.com/LimDongHyun99

    티스토리툴바