vendredi 27 février 2015

function to select combinations of characters from a string in c++

so here is my problem:


I need a function that given a string "qwer" of random length can select and put in an array all the possible sequences of characters long from 1 up to the length of the string. I am sorry, it is difficult to explain, but i think it should be easier to understand with an example. So if I have the string "qwer", i would like to have a function that create an array with the following entries:


qwer qwe wer qwr qer qw qe qr we wr er q w e r


Note that in the items with more than one character, the order of the characters must respect that of the original string (so for instance I want the item qwe but i do not want the idem ewq). It is thus not just a problem of permutations, but of permutations that respect the original order.


Also, as I said at the beginning, ideally the function should be able to handle strings of any length.


Do you know if a function like this exists? Or do you have any idea about how to create it? I'ma bit stuck with it..


Aucun commentaire:

Enregistrer un commentaire