Roy and Texting Robot
Practice
4.1 (36 votes)
Ad Hoc
Algorithms
Approved
Basic programming
Easy
Implementation
Open
Problem
74% Success 4848 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Roy frequently needs to use his old Nokia cell phone for texting whose keypad looks exactly as shown below.

enter image description here

You may be already familiar with the working of the keypad, however if you're not we shall see a few examples.

To type "b", we need to press "2" twice. To type "?" we need to press "1" thrice. To type "5" we need to press "5" four times. To type "0" we need to press "0" twice.

I hope that it's clear how the keypad is being used.

Now Roy has lot of text messages and they are pretty lengthy. So he devised a mechanical-hand-robot (with only 1 finger) which does the typing job. One drawback of this robot is its typing speed. It takes 1 second for single press of any button. Also it takes 1 second to move from one key to another. Initial position of the hand-robot is at key 1.

So if its supposed to type "hack" it will take 1 second to move from key 1 to key 4 and then 2 seconds to type "h".
Now again 1 second to move from key 4 to key 2 and then 1 second to type "a".
Since "c" is present at the same key as "a" movement time is 0. So it simply takes 3 seconds to type "c".
Finally it moves from key 2 to key 5 in 1 second and then 2 seconds to type "k". So in total it took 1+2+1+1+3+1+2= 11 seconds to type "hack".

Input:
First line contains T - number of test cases.
Each of next T lines contain a string S - the message Roy needs to send.
Each string is terminated by a newline escape sequence \n.

Output:
For each test case output the time taken by the hand-robot to type down the message.

Constraints:
1 ≤ T ≤ 50
1 ≤ |S| ≤ 1000 , where |S| denotes the length of string S
String is made of all the characters shown in the image above which are as follows:
"." (period), "," (comma), "?" (question mark), "!" (exclamation mark), [a-z] (small case english alphabets), "_" (underscore) and [0-9] (digits)

Note: We are using "_" underscore instead of " " empty space to avoid confusion

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
121 votes
Tags:
ApprovedEasyImplementationMathOpenReady
Points:20
30 votes
Tags:
Ad-HocBasic ProgrammingEasy
Points:20
9 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementationJavaPythonQuick SortSorting