사자자리

[C++] 백준 2920번: 음계 본문

C++/C++ 문제

[C++] 백준 2920번: 음계

renne 2022. 8. 24. 22:14

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

 

2920번: 음계

다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8

www.acmicpc.net

#include <iostream>
using namespace std;
int main() {
    int num[8], judge[8] = {0};
    for (int i = 0; i < 8; i++) {
        cin >> num[i];
        if (i != 0) {
            if (num[i - 1] < num[i]) judge[i] = 1;  //ascending
            if (num[i - 1] > num[i]) judge[i] = 0;  //descending
        }
    }
    for (int i = 2; i < 8; i++) {
        if (judge[i - 1] != judge[i]) {
            cout << "mixed";
            return 0;
        }
    }
    if (judge[1]) cout << "ascending";
    else cout << "descending";
    return 0;
}

'C++ > C++ 문제' 카테고리의 다른 글

[C++] 백준 11944번: NN  (0) 2022.08.24
[C++] 백준 10430번: 나머지  (0) 2022.08.17
[C++] 백준 1308번: D-Day  (0) 2022.08.05
[C++] 백준 4673번: 셀프 넘버  (0) 2022.08.03
[C++] 백준 10872번: 팩토리얼  (0) 2022.08.03
Comments