整数型配列やVectorを順列で一つ一つ処理をしていく方法
next_permutation関数を使う。
関数の使い方が少し独特である。
全ての順列を取得したい場合は、この関数に最初に与える範囲が、
昇順にソート済みになっていること。
つまりこの関数は、現在の状態から順々に並び替えて次の値を取得する、ということ
順列は自分で実装する場合は再帰を使うが、わりと手間である。
整数型配列
int a[5] = { 1,2,3,4,5 };
do {
for(int i = 0;i<4;i++){
cout << a[i] << " ";
}
cout << endl;
} while (next_permutation(a, a + 4));
Vector
vector<int> v = { 6,7,8,9 };
do {
for(auto V : v){
cout << V << " ";
}
cout << endl;
} while (next_permutation(v.begin(), v.end()));
文字列
string b = "abcde";
do {
cout << b << endl;
} while (next_permutation(b.begin(), b.end()));