Sorting??

C

Claudio

Hi there,

I am dealing with this "easy" C++ problem.

Introduction
Each number in a phone keyboard is associated to a set of tree chars.(i.e 2 = ABC).


Programming
Given 7 number in the range from 2 to 9 ( 0 and 1 not included ), the program has to write all the combinations of chars (2187 = 3^7)
in a file.

I am looking for some hints.


Thanks a lot for you help.
Claudio
 
P

Phlip

Claudio said:
I am dealing with this "easy" C++ problem.

Introduction
Each number in a phone keyboard is associated to a set of tree chars.(i.e
2 = ABC).


Programming
Given 7 number in the range from 2 to 9 ( 0 and 1 not included ), the
program has to write all the combinations of chars (2187 = 3^7) in a file.

I am looking for some hints.

Your post is most likely some kind of homework. Read "How do I get other
people to do my homework problem for me?" at:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2

Checking the FAQ before posting is always good.

That FAQ (I haven't read it yet) might warn you that simple questions might
still get answers like this:

You are asking not how to sort but how to count, meaning how to enumerate
values in a place-based notation. We are all familiar with the 10-digit
counting scheme we inherit from our primate ancestors. But your mission is
to count in base 24 (8 digits * 3 letters per digit).

So, iterate from 0 to 2187, convert each number from an integer to base 24,
and map each resulting digit onto a letter.
 
J

Jeff Schwab

Claudio said:
Each number in a phone keyboard is associated to a set of tree
chars.(i.e 2 = ABC).

Do you mean "three" characters?
Given 7 number in the range from 2 to 9 ( 0 and 1 not included ),

There are eight numbers in that range:

2 3 4 5
6 7 8 9
the program has to write all the combinations of chars (2187 = 3^7)
in a file.

That's the number of permutations, not the number of combinations.
I am looking for some hints.

Try the std::next_permutation algorithm.
 
D

Daniel T.

Claudio said:
I am dealing with this "easy" C++ problem.

Introduction
Each number in a phone keyboard is associated to a set of tree chars.(i.e 2 =
ABC).


Programming
Given 7 number in the range from 2 to 9 ( 0 and 1 not included ), the
program has to write all the combinations of chars (2187 = 3^7)
in a file.

I am looking for some hints.

Here is a hint. How would you do it by hand? Do it for a bit, then write
down how you are doing it. Then convert that to code.
 
C

Claudio

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

The forum should be used for such a thing or at least it was meant to be...

BTW thanks again for sharing your information with me.
 
O

osmium

Claudio writes:

[My mail program refuses to treat this as a quote]

OP start quote
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

The forum should be used for such a thing or at least it was meant to be...

OP end quote

I take it from the comment and the ellipses that you do not have an answer
to your question. After going through the thread again, I *finally* realize
it has something to do with seven digit telephone numbers and the fact that
most of those keys can be represented by three letters. For example, digit
5 can be J or K or L. But I have six of those kinds of keys on my (US)
telephone, not seven. I note that you are in Italy which, I suspect, is a
large part of the problem. Perhaps you use a 25 character version of the
latin alphabet.

After doing all this I still don't know where the 3^7 comes from! And what
you want to do.

Be very careful of typos (tree for three)
Look very carefully at the definitions for permutations and combinations
Make a distinction between numbers and digits and keys.
Note that we can't see *your* telephone.

Now rethink and repost.
 
K

Karl Heinz Buchegger

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top