Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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
Tags
more
Archives
Today
Total
관리 메뉴

자이의 프로그래밍

부등호 본문

Algorithm/Cases-Study

부등호

Xi_kor 2021. 5. 13. 19:50

큰 수와 작은 수를 구할때 0에서부터 n+1개를 1씩 커지게 하면서 벡터에 넣었고, 9에서부터  n+1개를 1씩 작아지게 하면서 벡터에 넣었다. 순열을 이용해 해결했다. 

#include <queue>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std; 

char arr[12];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    //큰것부터!
    vector <int> big;
    vector<int> small;

    for (int i = 0; i <= n; i++) {
        big.push_back(9 - i);
        small.push_back(i);
    }

    // big prev permutation small next permutation
    do {
        int status = 0;

        for (int i = 0; i < n; i++) {
            if (arr[i] == '>') {
                if (big[i] < big[i + 1]) status = 1;
            }
            else {
                if (big[i] > big[i + 1]) status = 1;
            }
            
        }
        if (status == 0) {
                break;
         }
    } while (prev_permutation(big.begin(), big.end()));

    do {
        int status = 0;

        for (int i = 0; i < n; i++) {
            if (arr[i] == '>') {
                if (small[i] < small[i + 1]) status = 1;
            }
            else {
                if (small[i] > small[i + 1]) status = 1;
            }
            
        }
        if (status == 0) {
            break;
        }
    } while (next_permutation(small.begin(), small.end()));

    //big-> small
    for (int i = 0; i < big.size(); i++) {
        cout << big[i];
    }
    cout << '\n';
    for (int i = 0; i < small.size(); i++) {
        cout << small[i];
    }
    return 0;
}

'Algorithm > Cases-Study' 카테고리의 다른 글

점프 1890  (0) 2021.05.13
물통 2251  (0) 2021.05.13
수이어쓰기1  (0) 2021.05.13
이동하기  (0) 2021.05.05
DSLR  (0) 2021.05.05