Showing posts with label HashTable. Show all posts
Showing posts with label HashTable. Show all posts

Tuesday, February 14, 2012

Convert Given Message Sequence in to Corrsponding Digits

The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. We would like to make it easier to write a message to your friend using a sequence of keypresses to indicate the desired characters. The letters are mapped onto the digits as shown below. To insert the character B for instance, the program would press 22. In order to insert two characters in sequence from the same key, the user must pause before pressing the key a second time. The space character ' ' should be printed to indicate a pause. For example, 2 2 indicates AA whereas 22 indicates B.



Example

hi      Case #1: 44 444
yes     Case #2: 999337777
foo bar Case #3: 333666 6660 022 2777
hello world   Case #4: 4433555 555666


Follow Up-Now Think if Question asked reverse e.g.
Given a telephone number print or produce all the possible telephone words or combinations of letters that can represent the given telephone number, then can you device an algorothm that will solve this problem efficiently. This is More Simple Then Previous One.