항상 백준은 입력방식때문에 코드가 들어가야함
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
8 1 7 2 6 3 5 4
이런식으로 숫자가 오름차슴 내림차순일때는
ascending desending 이라하고 이 두개가 아닐경우 mixed라고 출력한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a=0; String[] input = new String[8]; String str = sc.nextLine(); str = str.trim(); for(int i=0; i<str.length() ; i++ ){ if(!("".equals(str.substring(i, i+1).trim()) || str.substring(i, i+1).trim() == null) ){ input[a] = str.substring(i, i+1); a++; } } a=0; for(int i=1; i<8 ; i++){ a = Integer.parseInt(input[i]) - Integer.parseInt(input[i-1]); if(a>1 || a< -1){ break; } } if(a ==1){ System.out.println("ascending"); }else if( a== -1){ System.out.println("descending"); }else{ System.out.println("mixed"); } } } |