본문 바로가기
Baekjoon Online Judge

[BOJ] 백준 2920번: 음계 (Java)

by 프로그래 밍구 2023. 3. 28.

문제링크

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

 

2920번: 음계

다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8

www.acmicpc.net


나의코드

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        
        int[] arr = new int[8];
        
        for(int i = 0; i < 8; i++){
            arr[i] = Integer.parseInt(st.nextToken());            
        }
        
        boolean asc = true;
        boolean dsc = true;
        
        for(int j = 1; j < 8; j++){
            if(arr[j] >= arr[j - 1]){
                dsc = false;               
            }else if(arr[j] <= arr[j - 1]){
                asc = false;
            }
        }
        
        if(asc){
            System.out.print("ascending");
        }else if(dsc){
            System.out.print("descending");
        }else{
            System.out.print("mixed");
        }
    }
}

 

댓글