Algorithm/소프티어
[Softeer] 8단 변속기 - JAVA
LeeGangEun
2023. 8. 2. 23:19

풀이
간단한 문제이다.
입력된 배열이 오름차순이면 "ascending" 출력
내림차순이면 "descending" 출력
아닐경우 "mixed" 출력하면 된다.
이런경우는 배열을 생성하여 Arrays.equals 메서드를 사용하여 비교하는게 로직상 간단하다.
import java.util.*;
import java.io.*;
import java.util.stream.IntStream;
public class Main {
private static final int[] ascending = {1, 2, 3, 4, 5, 6, 7, 8};
private static final int[] descending = {8, 7, 6, 5, 4, 3, 2, 1};
public static void main(String[] args) throws IOException{
int[] arr = Arrays.stream(new BufferedReader(new InputStreamReader(System.in)).readLine()
.split(" "))
.mapToInt(Integer::parseInt)
.toArray();
if(Arrays.equals(ascending, arr)) System.out.println("ascending");
else if(Arrays.equals(descending, arr)) System.out.println("descending");
else System.out.println("mixed");
}
}