문제 분석

경우의 수 3가지에 대해서 출력한다

1->8

8->1

그 외

첫번째와 두번째 경우의 수를 체크하고 그렇지 않으면 예외인 경우를 출력했다.

오름차순일경우 1인지 체크 , 2인지 체크 ...

내림차순일경우 8인지 체크, 7인지 체크...

 

 

 

전체 소스


        int compare_one =1;
        int compare_eight = 8;
        
        for(int i=0; i<8; i++){
        int tmp = Integer.parseInt(st.nextToken());
        if(tmp==compare_one){
            compare_one++;
        }
        if(tmp==compare_eight){
            compare_eight--;
        }
        }
        String result = "";
        
        if(compare_one==9){
        result="ascending";
        }else if(compare_eight==0){
        result="descending";
        }else {
            result="mixed";

'알고리즘(종합) > Lv.2' 카테고리의 다른 글

프로그래머스 - 귤 고르기  (0) 2023.02.15
2001 - 파리퇴치  (0) 2022.11.14
1204 - 최빈수 구하기  (0) 2022.11.14
1954 - 달팽이 숫자  (0) 2022.11.13
1926 - 간단한 369 게임  (0) 2022.11.13
복사했습니다!