다음 순열과 마찬가지로 prev_permutation을 사용해주자 STL 찬양하자


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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> perm;
int main()
{
    bool last = false;
    int input = 0;
    cin >> input;
    for (int i = 0; i < input; ++i)
    {
        int n_input;
        cin >> n_input;
        perm.push_back(n_input);
    }
    last = prev_permutation(perm.begin(), perm.end());
    if (!last)
        cout << -1 << endl;
    else
    {
        for (auto itr = perm.begin(); itr != perm.end(); ++itr)
            cout << *itr << " ";
    }
    
    cout << endl;
    return 0;
}
cs


'백준 온라인 저지' 카테고리의 다른 글

백준 10819: 차이를 최대로  (0) 2018.07.17
백준 10974: 모든 순열  (0) 2018.07.17
백준 10972: 다음 순열  (0) 2018.07.17
백준 7576: 토마토  (0) 2018.07.16
백준 2146: 다리 만들기  (0) 2018.07.16

+ Recent posts