Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Last active August 29, 2015 14:14
Show Gist options
  • Save yohhoy/a95c4bea88a59a40ce82 to your computer and use it in GitHub Desktop.
Save yohhoy/a95c4bea88a59a40ce82 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <vector>
void pick(const std::vector<int>& v)
{
size_t sz = v.size();
for (size_t n = 1; n <= sz; ++n) {
std::vector<bool> sel(sz);
std::fill_n(sel.begin(), n, true);
do {
int r = 0;
for (size_t i = 0; i < sz; ++i) {
if (sel[i])
r = (r * 10) + v[i];
}
std::cout << r << std::endl;
} while (std::prev_permutation(sel.begin(), sel.end()));
}
}
int main()
{
pick({1,2,3});
// OUTPUT: 1 2 3 12 13 23 123
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment