#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
// 初期設定
vector<char> v1 {'a', 'b', 'c'};
printf("v1 : ");
for (auto x : v1)
printf("%c", x);
printf("\n");
// 次の並びを順に出力
bool b = true;
printf("次の並びを順に出力\n");
while (b) {
b = next_permutation(v1.begin(), v1.end());
if (b) {
printf(" ");
for (auto x : v1)
printf("%c", x);
}
else {
printf("\n");
printf(" 次の並び順は存在しません\n");
}
}
// 初期設定
vector<char> v2 {'b', 'c', 'a'};
printf("v2 : ");
for (auto x : v2)
printf("%c", x);
printf("\n");
// 前の並びを順に出力
b = true;
printf("前の並びを順に出力\n");
while (b) {
b = prev_permutation(v2.begin(), v2.end());
if (b) {
printf(" ");
for (auto x : v2)
printf("%c", x);
}
else {
printf("\n");
printf(" 前の並び順は存在しません\n");
}
}
// 初期設定
vector<char> v3 {'b', 'x', 'a'};
printf("v3 : ");
for (auto x : v3)
printf("%c", x);
printf("\n");
// 順列か?
b = is_permutation(v1.begin(), v1.end(), v2.begin());;
// b = is_permutation(v1.begin(), v1.end(), v2.begin(), v2.end());;
cout << boolalpha << " v2 は v1 の順列? : " << b << endl;
b = is_permutation(v1.begin(), v1.end(), v3.begin());;
// b = is_permutation(v1.begin(), v1.end(), v3.begin(), v2.end());;
cout << " v3 は v1 の順列? : " << b << endl;
return 0;
}