꾸르꾸르

[C++/STL] prev_permutation, next_permutation 순열찾기 본문

코딩, 알고리즘, 문제풀이/문법,알고리즘,C++,기타등등

[C++/STL] prev_permutation, next_permutation 순열찾기

GGUGGU- 2020. 4. 23. 00:03

2017. 10. 22에 쓰여진 글입니다.


#include <iostream>
#include <algorithm>        //permutation 위한 헤더
 
using namespace std;
 
int main()
{
    int a[3] = { 1,2,3 };
 
    cout << "다음순열찾기!" << endl;
    do {
        for (int i = 0; i < 3; i++)
            cout << a[i];
        cout << endl;
    } while (next_permutation(a, a + 3));
    cout << endl;
    cout << endl;
 
    int b[3] = { 3, 1, 2 };
    cout << "이전순열 찾기!" << endl;
    do {
        for (int i = 0; i < 3; i++)
            cout << b[i];
        cout << endl;
    } while (prev_permutation(b, b + 3));
 
    return 0;
}

 

※만약 벡터로 할꺼면

next_permutation(a.begin(),a.end());

Comments