ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 2920번: 음계
    코딩 2020. 7. 24. 12:00

    문제

    다장조는 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 중 하나를 출력한다.

     

    코드

    import java.util.Arrays;
    import java.util.Scanner;
    
    public class bj_2920 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    			Scanner sc = new Scanner(System.in);
    			int[] arr = new int[8];
    			int[] asc = {1, 2, 3, 4, 5, 6, 7, 8};
    			int[] desc = {8, 7, 6, 5, 4, 3, 2, 1};
    			
    			//
    			for(int i=0; i<8; i++)
    				arr[i] = sc.nextInt();
    			
    			//
    			if(Arrays.equals(arr,asc)) {
    				System.out.println("ascending");
    			} else if(Arrays.equals(arr, desc)) {
    				System.out.println("descending");
    			} else {
    				System.out.println("mixed");
    			}
    	}
    }

     

     

    '코딩' 카테고리의 다른 글

    백준 2798번: 블랙잭  (0) 2020.07.31
    백준 1260번: 나는 요리사  (0) 2020.07.25
    백준 2799번: 블라인드  (0) 2020.07.23
    백준 1159번: 농구 경기  (0) 2020.07.22
    프로그래머스: 오랜 기간 보호한 동물(1)  (0) 2020.06.15

    댓글

Designed by Tistory.