기본(Basic)
순열 출력하기
cepiloth
2021. 1. 6. 12:45
반응형
stl 의 nextnext_permutation 메소드를 사용하면 stl container 의 요소를 순열로 출력할 수 있다.
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <cstring>
using namespace std;
#define MAX_SIZE 100
#define INF 0x7fffffff
#define CENDL "\n"
#define ll long long
/*
* @memory - 2056 kb
* @time - 0 ms
*/
int main() {
cin.tie(0);
std::ios::sync_with_stdio(false);
vector<int> arr;
arr.push_back(1);
arr.push_back(2);
arr.push_back(3);
arr.push_back(9);
do
{
const int size = arr.size();
for(int i=0; i<size; i++) {
cout << arr[i];
}
cout << CENDL;
} while (next_permutation(arr.begin(), arr.end()));
return 0;
}
1239
1293
1329
1392
1923
1932
2139
2193
2319
2391
2913
2931
3129
3192
3219
3291
3912
3921
9123
9132
9213
9231
9312
9321
반응형