Thread: combination type problem

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    3

    combination type problem

    I have a puzzling problem and I can't seem to find a reasonable solution.
    For example I have a sequence of letters:
    A B C D
    A corresponds to the numbers 5 and 10;
    B = 11
    C = 6
    D = 12 and 7;
    I need to generate the different combinations in the same order as the original sequence of letters.
    The results should be as follows.
    5 11 6 12
    10 11 6 12
    5 11 6 7
    10 11 6 7

    I hope this makes sense and any help is greatly appreciated.

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    38
    What have you done so far?

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    that seems to lend itself to a recursive solution.
    have a function that takes a string (char *) as input
    Code:
    if the input is 0 (end of string), return
    ch = first character in the string
    for each number that ch as associated with it (could be one or more)
             print the number
             recursively call the function with the remaining characters
    then the issue is how to determine the numbers that are associated with each letter. for starters I would just use 'ifs' or 'switch' on the characters to get something working. then you could concoct a data structure that tells you the numbers for a given letter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sum combination
    By the_contractor in forum C Programming
    Replies: 5
    Last Post: 02-17-2010, 01:35 PM
  2. Combination program problem
    By Garland in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2007, 03:35 PM
  3. Every possible combination/best combination
    By ldb88 in forum C++ Programming
    Replies: 12
    Last Post: 07-19-2007, 02:48 AM
  4. Permutation and Combination
    By vasanth in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2002, 10:53 AM
  5. c++, characters combination problem
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-04-2001, 02:45 AM