Claudio said:
Thanks all for your help.
According to the FAQ,
I do not have to pass an examination.I have already done very long time ago and in other field.
I do not have to work with other programmers.So there is no way to cross each other.
I do not have homework to do.
As you probably have noticed
I did not ask for a program.I asked for help of someone having good experience in this kind of stuffs.
Just explanation....that's all
OK. So where is your problem? Is it a coding problem or do you have
problems in understanding what to do (coming up with an algorithm).
I assume the later.
Daniel already has provided a (big) hint:
How would you do it by hand?
This is always the first step when writing a program: Be sure you
can do the very same thing by using a paper and pencil. Do some
exercises and try to solve the problem (sometimes you can solve
a simplified version of your problem to solve some time) watching
yourself how you do it.
In the specific case:
given "56"
which words can be made from it.
Well first I would start with:
Hmm. '5'. What letters can it stand for. Hmm. J K L
Thus there will be a lot of words starting with 'J', but
which ones. Aha, '6' brings in the second letter which can be
M N O
So I have
J
JM
JN
JO
K
KM
KN
KO
L
LM
LN
LO
Hmm. What would change if I have eg. 562 instead of 56. Lets see
J
JM
JMA
JMB
JMC
JN
JNA
JNB
JNC
JO
JNA
JNB
JNC
K
KM
KMA
KMB
KMC
KN
KNA
KNB
KNC
...
Well. That looks like a lot of loops. By watching myself what did I do.
I started with the leftmost digit (5) and set up a loop to iterate
through all the letters that number could represent. For each of
those letters I start another loop which does the same thing for
the second digit. Combining both letters gives a string which takes
on all possible strings built from those 2 letters. In the 2nd
example I did the same but added another loop which does the same
thing with the 3rd digit. etc.
This is your idea. It's now up to you formalize it and turn it into
a program.
The forum should be used for such a thing or at least it was meant to be...
Not really. This forum doesn't dicuss on how you get ideas to solve
a specific problem. It kicks in if you have some problems in expressing
your idea in C++ or if you have some problems with the exact syntax
or semantics of some construct. In a sense it is like a class: 'How
to write correct english sentences'. In such a class you seldom will
find some hints on how to come up with an idea for a outstanding piece
of literature.