On Thu, 2014-01-30, bblaz wrote:
> On 01/30/14 16:34,
mary...@gmail.com wrote:
>> Hi.I joined recently to this group .I want write a program in c++
...
> std::string s = std::string(argv[1]) + std::string(argv[2]);
>
> do {
> std::cout << s << " ";
> } while (std::next_permutation(s.begin(), s.end()));
That doesn't seem to produce the result he wants -- in his examples
the elements of each original string never got permutated.
Let me try ... say the input strings are A and B.
You can construct a valid result by popping an element off A, another
one from B, ... and so on, A.size() + B.size() times. And you can do
that many different ways -- there are A.size() + B.size() decisions to
make, restricted by the fact that A.size() times you have to decide
"I'll pop from A". The rest of the time you need to pop from B.
I think I see a solution, so I'll stop there. Hint: next_permutation()
can still be used, but on the decision chain rather than the strings
themselves.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/
snipabacken.se> O o .