다음 순열
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<int> v;
for(int i=0;i<5;i++)
v.push_back(i);
sort(v.begin(), v.end());
do{
for(auto x:v)
cout<<x<<' ';
cout<<'\n';
}while(next_permutation(v.begin(), v.end()));
return 0;
}
다음 순열을 구할 수 있는 함수로 next_permutation()메서드를 활용할 수 있다. 매개 변수로는 시작 주소 그리고 마지막 주소를 넘겨주면 되겠다. 유의해야 할 사항으로는 sort()로 먼저 정렬을 해줘야 올바른 결과를 도출할 수 있다는 점이다.
Author And Source
이 문제에 관하여(다음 순열), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ssu_sunghun/다음-순열저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)