1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <algorithm>
#include <iostream>
#include <vector>
void print(const std::vector<int>& values, const std::vector<bool>& perm)
{
for(unsigned i = 0; i < perm.size(); ++i)
if(perm[i])
std::cout << values[i] << ' ';
std::cout << std::endl;
}
int main()
{
std::vector<int> values {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
for(unsigned i = 0; i <= values.size(); ++i) {
std::vector<bool> perm(values.size() - i, 0);
perm.resize(values.size(), 1);
do {
print(values, perm);
} while(std::next_permutation(perm.begin(), perm.end()));
}
}
|