i really need help

M

mary8shtr

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.
 
O

Osmium

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.

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
 
B

bblaz

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;
}
 
J

Jorgen Grahn

On 01/30/14 16:34, (e-mail address removed) 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
 
S

sg

Am 30.01.2014 22:16, schrieb Jorgen Grahn:
On 01/30/14 16:34, (e-mail address removed) 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.

Good guess (w.r.t. to what the OP wants)!
Good solution (w.r.t. to the guessed question)!
:)
 
R

red floyd

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top