combinations of substrings

Discussion in 'C++' started by zgfareed@gmail.com, Sep 23, 2007.

  1. Guest

    Can anyone suggest an algorithm or function to generate combinations/
    permutations of a group of substrings stored in a vector. The
    substrings consists of 3 letters and the resulting string combinations
    should be of a size that is a multiple of 3.
    , Sep 23, 2007
    #1
    1. Advertising

  2. sun1991 Guest

    On 24 Sep, 06:53, wrote:
    > Can anyone suggest an algorithm or function to generate combinations/
    > permutations of a group of substrings stored in a vector. The
    > substrings consists of 3 letters and the resulting string combinations
    > should be of a size that is a multiple of 3.


    check next_permutation() in STL.
    sun1991, Sep 24, 2007
    #2
    1. Advertising

  3. Kai-Uwe Bux Guest

    wrote:

    > Can anyone suggest an algorithm or function to generate combinations/
    > permutations of a group of substrings stored in a vector. The
    > substrings consists of 3 letters and the resulting string combinations
    > should be of a size that is a multiple of 3.


    First, the problem is obfuscated (I suspect, it is homework): the groups of
    3 letters just hide the abstract problem of generating permutations and
    combinations. So, first take the input data apart and create a

    std::vector< std::string >

    that stores those groups of three letters.

    Now, for permutations, life is easy because STL has next_permutation built
    in.


    For combinations, note that the problem of enumerating all combinations of
    length n from a set of k items is equivalent to listing all n-digit
    counting numbers in base k (because if you have such a number, each digits
    represents one of k items and you have made exactly n such choices). Thus,
    you could use a

    std::vector< unsigned int >

    and implement "add 1" in base k.


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Sep 24, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leandro Pardini

    Binary files, substrings and (un)packing.

    Leandro Pardini, Oct 25, 2003, in forum: Perl
    Replies:
    1
    Views:
    577
    Jim Gibson
    Oct 27, 2003
  2. Markus Dehmann

    regex: How to extract substrings?

    Markus Dehmann, Dec 10, 2005, in forum: Java
    Replies:
    2
    Views:
    784
    IchBin
    Dec 10, 2005
  3. Ying Yang
    Replies:
    9
    Views:
    612
    Mike Wahler
    Sep 27, 2003
  4. mrstephengross

    Compile typedef-ed substrings

    mrstephengross, Apr 4, 2005, in forum: C++
    Replies:
    7
    Views:
    385
  5. Replies:
    0
    Views:
    312
Loading...

Share This Page