All Combinations of the alphabet
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 15 of 24

Thread: All Combinations of the alphabet

Threaded View

  1. #1
    Join Date
    Apr 2003

    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:

    void main()
    const int NUMITEMS = 26;
    char items[100] = "";
    for(int w=0; w< NUMITEMS; w++)
    items[w] = (char)(start+w);
    items[NUMITEMS] = '\0';
    int num =0;
    char temp[26];
    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[0] = items[startPlace];
    temp[1] = '\0';
    last = NUMITEMS+1;

    int i=0;
    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.


    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This a survey!

HTML5 Development Center