본문 바로가기

알고리즘/JAVA

[JAVA] 백준 알고리즘 2920 : 음계

반응형


주어진 배열이 오름차순인지 아닌지 판단하는 문제



  문제







  소스


import java.util.*; public class Main {     public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int pre = sc.nextInt(); int val; String result = "mixed"; while(sc.hasNext()) { val = sc.nextInt(); if (pre < val && pre+1 == val) { result = "ascending"; } else if (pre > val && pre == val+1) { result = "descending"; } else { result = "mixed"; break; } pre = val; } System.out.println(result);     } }






  출처


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



반응형