문제 제목 : 음계
난이도 : 하
문제 유형 : 배열, 구현
추천 풀이 시간 : 15분 (못하면 2배 30분)
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.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
int[] arr = new int[8];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
Boolean asc = true;
Boolean desc = true;
for (int i = 0; i < arr.length - 1; i++) {
if (arr[i] < arr[i + 1]) {
desc = false;
} else if (arr[i] > arr[i + 1]) {
asc = false;
}
}
if (asc) {
System.out.println("ascending");
} else if (desc) {
System.out.println("descending");
} else {
System.out.println("mixed");
}
}
}
'Algorithm > BAEKJOON' 카테고리의 다른 글
[알고리즘-DP] 파도반 수열 (0) | 2023.01.20 |
---|---|
[알고리즘-DP] 2×n 타일링 (0) | 2023.01.20 |
[자료구조-큐] 프린터 큐 (0) | 2023.01.20 |
[자료구조-스택] 스택 수열 (2) | 2023.01.20 |
[자료구조-배열] 블랙잭 (0) | 2023.01.19 |