I've got a string with eight characters in it, eg abcdefgh
. I need to generate all possible 10-character combinations of this string.
For example, all 2-character combinations of this string would be ab
bc
cd
ef
gh
ac
ad
ae
af
ah
, etc.
I thought of doing something like this but I couldn't figure out how to get it working.
What should I do? Is there a simple algorithm I'm missing?
You can use 2 pointers, one on the letter t the start of your string, who is incremented a each time you are on '/0' and the second who is simply incremented on each turn of your loop with a condition fo you don't rewrite an older combination.
aa ab ac ... bb bc ...
Edit :
No need condition, only the reset of your second pointer have to be 1 on the first pointer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.