• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wordFinder

 
eLL Pascual
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really want to make a program that is accepting integer values and I want that program to print all possible letter combinations assigned to each number or maybe not all. Just like when you type 23, the program should print "ad ae af bd be bf cd ce cf".

How can I do that?

Please help me. Thanks.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand how one gets from "23" to the list you mention. Can you describe the algorithm to us?

What do you have so far?
 
eLL Pascual
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im sorry for not explaining my problem very clearly...
In your nokia cellphone, there are corresponding letters in every number right?

That's how the number 23 got the letters ad ae af etc... the program will print all possible letter combinations.

These are the letters:
number 1: special characters
number 2: abc
number 3: def
number 4: ghi
number 5: jkl
number 6: mno
number 7: pqrs
number 8: tuv
number 9: wxyz
number 0: space

I haven't started yet because I dont know how.
Actually I already tried it. I used nesting for loop and if-else but the problem is my program is not printing anything correctly. So my problem is merely everything.
 
Henry Wong
author
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried a recursive solution? This is a classic homework problem for recursion.

Henry
 
Norm Radder
Ranch Hand
Posts: 728
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a nested loop problem, except the number of nestings isn't fixed.
If it were fixed, say at 2 as per your example, there would be a nested loop with the outer one picking up one letter at a time and the inner loop then appending one letter at a time to the one from the outer loop.
Now think how to do this using recursion. Put the letters into a 2 dimensional array with the first index being the number and the second index being the letters for that number.
This is off the top of my head, of course.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic