[백준] 2920번

park jinwoo·2022년 12월 23일
0

백준

목록 보기
62/94

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

1부터 8까지 차례대로 연주한다면 ascending, 8부터 1까지 차례대로 연주한다면 descending, 둘 다 아니라면 mixed 이다.

<script>
#define _CRT_SEUCRE_NO_WARNING
#include <stdio.h>

int main(void)
{
    int input[9];
    int result = 0; // 결과값 변수

    for (int i = 0; i < 8; i++) {
        scanf("%d", &input[i]);
    }

    for (int j = 0; j < 7; j++) {
        if (input[j] + 1 == input[j + 1]) {
            result += 1;
        }
        else if (input[j] - 1 == input[j + 1]) {
            result -= 1;
        }
    }

    if (result == 7) {
    // result + 1 이 7번 이루어 졌을 때, 1씩 올라가는 오름차순
        printf("ascending");
    }
    else if (result == -7) {
    // result - 1 이 7번 이루어 졌을 때, 1씩 내려가는 내림차순
        printf("descending");
    }
    else {
    // 그 외 result값이 7이나 -7이 아닐 경우
        printf("mixed");
    }
        
    return 0;
}
</script>

0개의 댓글