470,632 Members | 2,041 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

combinations of substrings

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 '07 #1
2 2089
On 24 Sep, 06:53, zgfar...@gmail.com 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.

Sep 24 '07 #2
zg******@gmail.com 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
Sep 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Leandro Pardini | last post: by
4 posts views Thread by spam | last post: by
3 posts views Thread by Will McGugan | last post: by
3 posts views Thread by Girish Sahani | last post: by
8 posts views Thread by girish | last post: by
2 posts views Thread by Pilcrow | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.