<접근 방법>

1. ascending인지를 체크한다.

1-1. ascending이면 "ascending"을 출력 후 종료

2. descending인지를 체크한다.

2-1. descending이면 "descending"을 출력 후 종료

3. ascending과 descending이 모두 아니면 "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
#include <iostream>
 
using namespace std;
int main(int argc, char *argv[]) {
    int input[8];
    bool ascending = true;
    bool descending = true;
    
    for(int i=0; i<8; i++)
        cin >> input[i];
    
    for(int i=0; i<8; i++) {
        if(input[i] != (i+1)) {
            ascending = false;
            break;
        }
    }
    
    if(!ascending) {
        for(int i=7; i>=0; i--) {
            if(input[7-i] != (i+1)) {
                descending = false;
                break;
            }
        }
    }
    
    if(ascending)
        cout << "ascending" << endl;
    else if(descending)
        cout << "descending" << endl;
    else
        cout << "mixed" << endl;
        
    return 0;
}
cs


'C & C++ > Baekjoon' 카테고리의 다른 글

백준 4344 - 평균은 넘겠지  (0) 2017.12.27
백준 2941 - 크로아티아 알파벳  (0) 2017.12.27
백준 2908 - 상수  (0) 2017.12.27
백준 2839 - 설탕 배달  (0) 2017.12.27
백준 2742 - 기찍 N  (0) 2017.12.27

+ Recent posts