본문 바로가기
알고리즘 문제연습/기초 알고리즘

[029] 음계 (백준 2920번)

by 은z 2021. 6. 17.
package AlgorithmEasy;

import java.util.Arrays;
import java.util.Scanner;

public class Algorithm29 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] input = new int[8];
		String result = "";
		System.out.println("1부터 8까지의 수를 입력하세요 >> ");
		
		for(int i = 0; i < input.length; i++) {
			input[i] = sc.nextInt();
		}
		//System.out.print(Arrays.toString(input));
		
	Lable:for(int i = 0; i < input.length-1; i++) { // 0 1 2 3 4 5 6 
			for(int j = i+1; j < input.length; j++) { // 
				if(input[i]+1 == input[j]) { //오름차순인 경우
					result = "ascending";
					break;
				}else if(input[i]-1 == input[j]) { //내림차순인 경우
					result = "descending";
					break;
				}else { //한번이라도 여기들어오면 끝
					result = "mixed";
					break Lable;
				}
			}
		}
		System.out.println(result);
	}
	
}

 

댓글