본문 바로가기
알고리즘 문제풀이/백준

[알고리즘/백준] 2920 음계(자바)

by jeonghaemin 2021. 9. 19.
728x90

문제

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

풀이 코드

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] ascending = {1, 2, 3, 4, 5, 6, 7, 8};
        int[] descending = {8, 7, 6, 5, 4, 3, 2, 1};
        int[] arr = new int[8];

        StringTokenizer st = new StringTokenizer(br.readLine());
        for (int i = 0; i < 8; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }

        if (Arrays.equals(arr, ascending)) {
            System.out.println("ascending");
        } else if (Arrays.equals(arr, descending)) {
            System.out.println("descending");
        } else {
            System.out.println("mixed");
        }

    }
}

댓글