Edited after receiving answers
There are great answers here. I like Josh because he is so smart and uses C ++. However, I decided to accept Dave's answer because of its simplicity and recursion. I tested both of them, and they both gave the same correct results (albeit in a different order). So thanks again to everyone.
Say I have a string s of characters s [0]: s [N] and where each char s [i] <= s [i + 1] For example, a string
aaacdddghzz
I want to generate all combinations of substrings, keeping the same relationship between characters.
So for example, I would get
a
aa
aaa
ad
aad
aaad
add
aadd
aaadd
addd
aaddd
aaaddd
d
dd
ddd
.
.
.
ac
aac
.
.
.
acdddghzz
aacdddghzz
aaacdddghzz
But not
ca
hdz
...etc
Now I know how to determine how many combinations are. You create a histogram of the frequency of letters in a row. So in the example above it will be
aaacdddghzz
a=3
d=3
c=1
g=1
h=1
z=2
(a+1)(c+1)(d+1)(g+1)(h+1)(z+1) = 4*4*2*2*2*3 = 384. 384 , s [i] <= s [i + 1].
, , 384 ? , , , , . , . . ++, .