-
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.
-
What have you done so far?
-
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.