I have a vector of strings with values {"Soa", "8", "m", "4", "8"}
I would like to print all permutations without repetitions (but duplicates allowed like "8" in vector above) for specified size n
from array of size k
. I have searched for solution to this but can't find any for this case.
Code at the moment is:
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
int main()
{
std::vector<std::string> arr = { "Soa", "4", "m", "8", "8" };
std::sort(arr.begin(), arr.end());
do {
for(auto& i: arr)
std::cout << i;
std::cout << '\n';
} while(std::next_permutation(arr.begin(), arr.end()));
}
This code prints all permutations for size of vector only (n=k
), so it prints what I need but for n=5
. What I would like is to specify n
, so for example for n=2
to generate those permutations (order in which they are printed dosen't matter):
48
4Soa
4m
84
88
8Soa
8m
Soa4
Soa8
Soam
m4
m8
mSoa
EDIT: Solution linked by Nathan dosen't work, it treats 84 same as 48. Still looking for solution.