별의 공부 블로그 🧑🏻‍💻
728x90
728x170

문제

다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다.

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

연주한 순서가 주어졌을 때, 이것이 ascending인지, descending인지, 아니면 mixed인지 판별하는 프로그램을 작성하시오.

 

 

입력

첫째 줄에 8개 숫자가 주어진다. 이 숫자는 문제 설명에서 설명한 음이며, 1부터 8까지 숫자가 한 번씩 등장한다.

 

 

출력

첫째 줄에 ascending, descending, mixed 중 하나를 출력한다.

 

 

예제 입력

 1 2 3 4 5 6 7 8

 

예제 출력

 ascending

 

 

힌트

 

 

출처

Contest  >  Croatian Open Competition in Informatics  >  COCI 2009/2010  > Contest #1 1번

· 문제를 번역한 사람: baekjoon 

· 문제의 오타를 찾은 사람: thinksong1



알고리즘 분류

· 배열

 

 

코드

 

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
38
#include <iostream>
 
#define N 8
 
using namespace std;
 
int main()
{
    int ary[N], isAscending = 0, isDescending = 0;
 
    for (int i = 0; i < N; i++) {
        cin >> ary[i];
    }
    
    // checking order
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            if (ary[j] < ary[i]) {        // 내림 차순일 경우                                                                    
                isDescending = 1;
            }
            else if (ary[j] > ary[i]) {    // 오름 차순일 경우
                isAscending = 1;
            }
        }
    }
 
    if ((isAscending == 1&& (isDescending == 1)) {
        cout << "mixed" << endl;
    }
    else if ((isAscending == 1&& (isDescending == 0)) {
        cout << "ascending" << endl;
    }
    else if ((isAscending == 0&& (isDescending == 1)) {
        cout << "descending" << endl;
    }
 
    return 0;
}
cs
728x90
그리드형(광고전용)
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖