Back before Smart Phones took over the universe, cell phones had a gray and black screen, and 12 buttons laid out like their predecessor, non-cell phones. The 12 buttons were 0 through 9, plus '#' and '*'. Here's an example:
Sending text messages on these phones was a pain, but the cell phone manufacturers developed something called "T9" to make it easier - see https://en.wikipedia.org/wiki/T9_(predictive_text).
With T9, you would simply type the numeric keys that spell the word you want. Given the phone above, you could type "the" with "843" and "bad" with 223. After you typed your word, the T9 system would display the word that matched the keystrokes, and that their system thought was the most likely word for you to type. If there were multiple words that had the same keystrokes, you would press '#' to cycle through all of the words with the same keystrokes.
This topcoder problem has you implement the T9 functionality, but there are a few wrinkles:
Your goal is to create a map, whose keys are the keystrokes you need for a word, and whose vals are vectors of the words that correspond to the keystrokes. Eventually, you will want the vectors to be sorted.
Let's use example two to illustrate. You are going to want a map with two keys: "223" and "843". Here are the keys and vals:
We're going to build up a solution. You should do every step here, and then test to make sure you've gotten it done correctly.
Examples 0 through 4:
a maps to 2 b maps to 2 c maps to 2 d maps to 3 e maps to 3 f maps to 3 g maps to 4 h maps to 4 i maps to 4 j maps to 5 k maps to 5 l maps to 5 m maps to 6 n maps to 6 o maps to 6 p maps to 7 q maps to 7 r maps to 7 s maps to 7 t maps to 8 u maps to 8 v maps to 8 w maps to 9 x maps to 9 y maps to 9 z maps to 9 |
Example 5:
a maps to 4 b maps to 5 c maps to 5 d maps to 3 e maps to 3 f maps to 5 g maps to 5 h maps to 8 i maps to 8 j maps to 6 k maps to 6 l maps to 3 m maps to 9 n maps to 5 o maps to 4 p maps to 6 q maps to 2 r maps to 2 s maps to 7 t maps to 6 u maps to 4 v maps to 7 w maps to 7 x maps to 6 y maps to 4 z maps to 4 |
Example 0:
Word bad = 223 |
Example 1:
Word the = 843 Word tie = 843 |
Example 2:
Word bad = 223 Word ace = 223 Word aad = 223 Word aae = 223 Word aaf = 223 Word acf = 223 Word acd = 223 Word the = 843 Word tie = 843 |
Example 3:
Word the = 843 Word tie = 843 Word bad = 223 Word ace = 223 Word aad = 223 Word aae = 223 Word aaf = 223 Word acf = 223 Word acd = 223 |
Example 4:
Word bad = 223 Word ace = 223 Word aad = 223 Word aae = 223 Word tie = 843 Word aaf = 223 Word acf = 223 Word acd = 223 Word the = 843 |
Example 5:
Word xktgmfmoqlmivm = 66659594239879 Word hmthr = 89682 Word tpjgmnmaremiwm = 66659594239879 Word tpjcmnmyrlmhvm = 66659594239879 Word xkpnmgmzqdmhsm = 66659594239879 Word wqopvvmiig = 7246779885 Word melbcbqeeg = 9335552335 Word jkxnmbmardmhwm = 66659594239879 Word kpxnmcmyqlmism = 66659594239879 Word wrztvsmhhf = 7246779885 Word srztssmiic = 7246779885 Word pxtgmfmyrdmhwm = 66659594239879 Word vqoxswmiin = 7246779885 Word wryksvmihb = 7246779885 Word ptjfmbmoremhvm = 66659594239879 |
Example 0: Key 223: bad |
Example 1: Key 843: the tie |
Example 2: Key 223: bad ace aad aae aaf acf acd Key 843: the tie |
Example 3: Key 223: bad ace aad aae aaf acf acd Key 843: the tie |
Example 4: Key 223: bad ace aad aae aaf acf acd Key 843: tie the |
Example 5: Key 66659594239879: xktgmfmoqlmivm tpjgmnmaremiwm tpjcmnmyrlmhvm xkpnmgmzqdmhsm jkxnmbmardmhwm kpxnmcmyqlmism pxtgmfmyrdmhwm ptjfmbmoremhvm Key 7246779885: wqopvvmiig wrztvsmhhf srztssmiic vqoxswmiin wryksvmihb Key 89682: hmthr Key 9335552335: melbcbqeeg |
Example 0: Key 223: bad |
Example 1: Key 843: the tie |
Example 2: Key 223: aad aae aaf acd ace acf bad Key 843: the tie |
Example 3: Key 223: aad aae aaf acd ace acf bad Key 843: the tie |
Example 4: Key 223: aad aae aaf acd ace acf bad Key 843: the tie |
Example 5: Key 66659594239879: jkxnmbmardmhwm kpxnmcmyqlmism ptjfmbmoremhvm pxtgmfmyrdmhwm tpjcmnmyrlmhvm tpjgmnmaremiwm xkpnmgmzqdmhsm xktgmfmoqlmivm Key 7246779885: srztssmiic vqoxswmiin wqopvvmiig wryksvmihb wrztvsmhhf Key 89682: hmthr Key 9335552335: melbcbqeeg |
Example 0: String = 223. Number of '#': 0 Space String = 223. Number of '#': 0 |
Example 1: Space String = 843. Number of '#': 1 Space Space Space String = 843. Number of '#': 1 Space Space Space |
Example 2: String = 223. Number of '#': 1 Space String = 223. Number of '#': 6 Space Space String = 843. Number of '#': 1 Space |
Example 3: String = 843. Number of '#': 0 Space Space String = 223. Number of '#': 1 Space String = 223. Number of '#': 6 |
Example 4: String = 223. Number of '#': 1 Space String = 223. Number of '#': 6 |
Example 5: Space Space String = 7246779885. Number of '#': 2 Space Space Space Space Space Space String = 89682. Number of '#': 0 Space Space Space Space Space String = 7246779885. Number of '#': 2 Space Space Space Space String = 7246779885. Number of '#': 1 Space Space Space Space String = 89682. Number of '#': 0 Space Space Space Space String = 9335552335. Number of '#': 0 Space Space String = 66659594239879. Number of '#': 3 Space Space Space |