Post

[BOJ 2920] 음계

Baekjoon Online Judge 2920(Java 11)
[음계] 문제 풀이

[BOJ 2920] 음계

-> 문제 바로가기



시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초128 MB122425695506077257.916%

문제


  • 다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, …, C를 8로 바꾼다.

  • 1부터 8까지 차례대로 연주한다면 ascending, 8부터 1까지 차례대로 연주한다면 descending, 둘 다 아니라면 mixed 이다.

  • 연주한 순서가 주어졌을 때, 이것이 ascending인지, descending인지, 아니면 mixed인지 판별하는 프로그램을 작성하시오.


입력


  • 첫째 줄에 8개 숫자가 주어진다. 이 숫자는 문제 설명에서 설명한 음이며, 1부터 8까지 숫자가 한 번씩 등장한다.


출력


  • 첫째 줄에 ascending, descending, mixed 중 하나를 출력한다.


예제 1


1
2
// 입력
1 2 3 4 5 6 7 8
1
2
// 출력
ascending

예제 2


1
2
// 입력
8 7 6 5 4 3 2 1
1
2
// 출력
descending

예제 3


1
2
// 입력
8 1 7 2 6 3 5 4
1
2
// 출력
mixed


출처



알고리즘 분류








제출



내 제출


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.*;
import java.util.*;

public class Main {

    public static void solution() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");

        int[] arr = new int[8];
        String str = "";

        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }

        for (int i = 0; i < arr.length; i++) { // ascending, mix 여부를 구하는 연산자
            if (arr[i] == i + 1) {
                str = "ascending";
            } else {
                str = "mixed";
                break;
            }
        }
        if (arr[0] == 8 && arr[1] == 7 && arr[2] == 6 && arr[3] == 5 && arr[4] == 4 && arr[5] == 3 && arr[6] == 2) { // descending 여부를 구하는 연산자
            str = "descending";
        }
        bw.write(str);

        bw.flush();
        bw.close();
        br.close();
    }


    public static void main(String[] args) throws IOException {
        solution();
    }
}


런타임메모리
100 ms14164 KB


Reference


This post is licensed under CC BY 4.0 by the author.