Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

i really need help

79 views
Skip to first unread message

mary...@gmail.com

unread,
Jan 30, 2014, 10:34:04 AM1/30/14
to
Hi.I joined recently to this group .I want write a program in c++ language.one program in c++ that receive two char array from user and print all of state built by this tow arryas.for example users enter "abc" and "mn".program should show abcmn , abmnc , amnbc , mnabc ,mabcn ,manbc, mabnc , ambnc ,ambcn ,abmcn as output.pleas answer me.I very thought on this solution.but I couldn't solve it.and i need it early.I thanks very much if anyone answer me faster.

Osmium

unread,
Jan 30, 2014, 1:29:07 PM1/30/14
to
I may not understand your problem. Forging ahead.

I plugged <permutations c++> into google and got a lot of results. One of
the early ones that might be at an appropriate level is this one:

http://www.codeproject.com/Articles/4895/Permutations-in-C


bblaz

unread,
Jan 30, 2014, 3:14:07 PM1/30/14
to
On 01/30/14 16:34, mary...@gmail.com wrote:
> Hi.I joined recently to this group .I want write a program in c++ language.one program in c++ that receive two char array from user and print all of state built by this tow arryas.for example users enter "abc" and "mn".program should show abcmn , abmnc , amnbc , mnabc ,mabcn ,manbc, mabnc , ambnc ,ambcn ,abmcn as output.pleas answer me.I very thought on this solution.but I couldn't solve it.and i need it early.I thanks very much if anyone answer me faster.
>

#include <iostream>
#include <algorithm>
#include <string>

int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: ./permutations input1 input2 \n";
std::exit(1);
}

std::string s = std::string(argv[1]) + std::string(argv[2]);

do {
std::cout << s << " ";
} while (std::next_permutation(s.begin(), s.end()));
std::cout << std::endl;

return 0;
}

Jorgen Grahn

unread,
Jan 30, 2014, 4:16:16 PM1/30/14
to
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 .

sg

unread,
Jan 30, 2014, 9:23:40 PM1/30/14
to
Good guess (w.r.t. to what the OP wants)!
Good solution (w.r.t. to the guessed question)!
:-)

> /Jorgen

red floyd

unread,
Jan 31, 2014, 12:24:29 PM1/31/14
to
On 1/30/2014 7:34 AM, mary...@gmail.com wrote:
> Hi.I joined recently to this group .I want write a program in c++ language.one program in c++ that receive two char array from user and print all of state built by this tow arryas.for example users enter "abc" and "mn".program should show abcmn , abmnc , amnbc , mnabc ,mabcn ,manbc, mabnc , ambnc ,ambcn ,abmcn as output.pleas answer me.I very thought on this solution.but I couldn't solve it.and i need it early.I thanks very much if anyone answer me faster.
>

Your answer may be found in the FAQs. In particular, FAQ 5.2.

0 new messages