Class MultiTapTextEntry

java.lang.Object
  extended by MultiTapTextEntry

public class MultiTapTextEntry
extends java.lang.Object

From Google code jam 2010 qualification round, South Africa. The release tests for this example are the small and large practice inputs from the code jam.

Even before phones with keyboards and touch screens, you could send text on mobile phones. One of the methods used was multi-tap text entry.

The 2 key is labeled with abc; the 3 key with def; each key 2-9 is labeled with 3 letters, except 7 which is labeled pqrs and 9 which is labeled wxyz.

To insert the character E for instance, the program would press 33 (the digit 3 since e appears on the 3 key; twice since it is the second letter listed for 3). 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.

Each message will consist of only lowercase characters a-z and space characters ' '. Pressing zero emits a space.

Note that the Google code jam problem incorrectly describes this as T9 text entry.


Method Summary
static java.lang.String getMultitapSpelling(java.lang.String txt)
          Return the multi-tap encoding of a message.
static void main(java.lang.String[] args)
          Read input and write output using the format described in the Google code jam problem.

Method Detail

getMultitapSpelling

public static java.lang.String getMultitapSpelling(java.lang.String txt)
Return the multi-tap encoding of a message. Input is only lowercase letters and spaces. Output should be only digits and spaces.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Read input and write output using the format described in the Google code jam problem. The first line contains the number of test cases, each following line contains a test case. The output is one line for each test case, with the format
 Case #n: output
 
where n is the test case number (starting at 1) and the output is the result of encoding that test case. If a file is provided on the command line, read that, otherwise read from standard input. Output is written to standard output.

Throws:
java.lang.Exception


Web Accessibility