473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sorting??

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
Jul 22 '05 #1
6 1714
Claudio wrote:
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-lit...t.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.

--
Phlip
http://www.c2.com/cgi/wiki?DevNull
-- But all the other programmers were doing it! --

Jul 22 '05 #2
Claudio wrote:
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.

Jul 22 '05 #3
"Claudio" <c.*******@tin.it> wrote:
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.
Jul 22 '05 #4


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.
Jul 22 '05 #5
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.
Jul 22 '05 #6
Claudio wrote:

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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.