April 21st, 2003, 12:35 AM
All Combinations of the alphabet
OK, so I'm trying to write some C++ code that will generate all combinations, of any size of the letters of the alphabet. so...
etc etc etc. the code I have now get a good amount of the combinations, but only keeps the combinations in oreder. ex: it gets ABE but not ACE, it gets CDF, but not CEF. here's what I have so far:
const int NUMITEMS = 26;
char items = "";
for(int w=0; w< NUMITEMS; w++)
items[w] = (char)(start+w);
items[NUMITEMS] = '\0';
int num =0;
for(int startPlace=0; startPlace<NUMITEMS; startPlace++)
for(int length=1; length<NUMITEMS-(startPlace-1); length++)
for(int last=startPlace+length-1; last<NUMITEMS; last++)
if(length == 1)
temp = items[startPlace];
temp = '\0';
last = NUMITEMS+1;
temp[i] = items[startPlace+i];
temp[length-1] = items[last];
temp[length] = '\0';
//Code to calculate the best answer.
cout << temp<< "\n";
can anyone tweak my solution to help me get all of them or give come up with some code that will get them all?
PS: I'm looking for combinations, not permitations. Order Doesn't matter.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!