i really need help

Discussion in 'C++' started by mary8shtr, Jan 30, 2014.

  1. mary8shtr

    mary8shtr Guest

    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.
     
    mary8shtr, Jan 30, 2014
    #1
    1. Advertisements

  2. mary8shtr

    Osmium Guest

    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
     
    Osmium, Jan 30, 2014
    #2
    1. Advertisements

  3. mary8shtr

    bblaz Guest

    #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;
    }
     
    bblaz, Jan 30, 2014
    #3
  4. mary8shtr

    Jorgen Grahn Guest

    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, Jan 30, 2014
    #4
  5. mary8shtr

    sg Guest

    Am 30.01.2014 22:16, schrieb Jorgen Grahn:
    Good guess (w.r.t. to what the OP wants)!
    Good solution (w.r.t. to the guessed question)!
    :)
     
    sg, Jan 31, 2014
    #5
  6. mary8shtr

    red floyd Guest

    Your answer may be found in the FAQs. In particular, FAQ 5.2.
     
    red floyd, Jan 31, 2014
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.