CCC '06 J3 - Cell-Phone Messaging

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2006 Stage 1, Junior #3
1 2 3 4 5 6 7 8 9 0 abc def ghi jkl mno pqrs tuv wxyz _ </g>

Joe Coder has just received a cell phone for his birthday. At first he was not so excited about it, since he does not like to talk that much, nor listen for that matter, and he hates being interrupted by phone calls while coding or playing his favourite computer game. But, Joe learned that he can talk to his friends and also send e-mails. That made the phone cool.

In order to fit the 26 letters of the alphabet onto the keys of a cell phone, several letters are assigned to each key, as shown on the diagram. To write a text message, we have to choose a letter from a set assigned to a key. The first letter on a key is chosen by pressing the key once, the second letter by pressing the key twice, third letter by pressing the key three times, and so on.

For example, to write a we press the key 2 once and we are done; to write dada we press 3232—four key presses; and to write bob we press 2266622.

An obvious issue is how to write two consecutive letters on the same key, for example in abba or cell. The problem is solved by introducing a time-out feature: a letter currently displayed is chosen when another key is pressed, but also after a pause, i.e., a time out. Hence for example, to write abba we press 2-pause-22-pause-22-pause-2; to write cell we press 22233555-pause-555; or to write www we press 9-pause-9-pause-9.

This kind of typing takes some time, and Joe is working on a program to calculate how much time is needed to type certain words. His assumption is that he spends one second per press, and whenever he makes a pause he loses an additional two seconds. You are to help him to calculate the minimal time needed to type a message, under the above assumptions.

Input

Each line of input contains a word consisting only of lowercase letters. Words have at most 20 characters. Input will be given from the keyboard, and the program should stop reading input when the word halt has been entered.

Output

For each input word (excluding the word halt), print (on the screen) the minimal number of seconds needed to type in the word, with one number of output per line.

Sample Input

a
dada
bob
abba
cell
www
halt

Sample Output

1
4
7
12
13
7

Comments


  • 1
    EthFng64  commented on Sept. 12, 2024, 11:07 p.m.

    only one test case?


  • 1
    leoliu93233  commented on Jan. 14, 2024, 2:02 a.m.

    this problem is so outdated after 16 years


    • 0
      Peter2023  commented on Jan. 15, 2024, 6:13 p.m.

      Fr


  • 3
    dchoo333  commented on Oct. 30, 2021, 7:06 a.m. edited

    The test cases are weak. I don't think one test case is enough, or you can include more inputs in the only test case.


  • 0
    jintong_jia  commented on April 24, 2021, 6:12 a.m.

    it is so tiring to make a dict for this thing


  • 31
    Dav_Did  commented on Dec. 20, 2020, 5:49 p.m.

    "and he hates being interrupted by phone calls while coding or playing his favourite computer game."

    Dude you have a computer and decide to suffer us with a cellphone.


  • 53
    anthony_  commented on July 6, 2020, 2:14 p.m. edited

    The base time it takes to press each key, as a Python dictionary:

    time = {'a': 1, 'b': 2, 'c': 3, 'd': 1, 'e': 2, 'f': 3, 'g': 1, 'h': 2, 'i': 3, 'j': 1, 'k': 2, 'l': 3, 'm': 1, 'n': 2, 'o': 3, 'p': 1, 'q': 2, 'r': 3, 's': 4, 't': 1, 'u': 2, 'v': 3, 'w': 1, 'x': 2, 'y': 3, 'z': 4}
    

    • 9
      QiQi  commented on Dec. 4, 2021, 7:43 p.m. edit 2

      And here's which key each letter is on (to find pauses):

      letter_on = {'a': 2, 'b': 2, 'c': 2, 'd': 3, 'e': 3, 'f': 3, 'g': 4, 'h': 4, 'i': 4, 'j': 5, 'k': 5, 'l': 5, 'm': 6, 'n': 6, 'o': 6, 'p': 7, 'q': 7, 'r': 7, 's': 7, 't': 8, 'u': 8, 'v': 8, 'w': 9, 'x': 9, 'y': 9, 'z': 9}
      

    • 0
      Amateur360  commented on Dec. 21, 2020, 2:48 a.m. edit 3

      Also, for those who are programming in Java, you would use a hashmap from java.util, which would contain each letter and the time it takes to press their respective keys. You would basically do time.put(letter, seconds) to put something it and time.get(letter) to get the time to press a certain letter.


    • 1
      Badmode  commented on Dec. 12, 2020, 12:55 a.m.

      Brilliant. Thanks for the dictionary!


    • 3
      blueishfiend692  commented on Sept. 12, 2020, 7:56 p.m.

      Thank you good sir!!!


  • -1
    kylezheng7  commented on April 26, 2020, 8:19 p.m. edited

    Can someone plz explain how abba takes 12 seconds to type a - 1, b - 2, pause - 2, b - 2, a - 1

    1 + 2 + 2 + 2 + 1 = 12????????

    Edit: nvm


    • 3
      littlemouseAM  commented on April 29, 2020, 5:19 p.m.

      abba takes 12 seconds because they are all on the same key - 2. therefore, it is a - 1, pause, b - 2, pause, b - 2, pause, a - 1.

      1 + 2 + 2 + 2 + 2 + 2 + 1 = 12