#P9856. GPS Cursor Navigation
GPS Cursor Navigation
GPS Cursor Navigation
Sandy received a GPS unit for her birthday. The device lets her record waypoints along local hiking trails by entering a description using a limited keypad. The keypad consists of four directional buttons and an accept button. The on‐screen grid contains letters and symbols, arranged as shown below.
The grid layout is defined as follows (each cell is identified by its row and column indices starting at 0):
Row 0: A B C D E F Row 1: G H I J K L Row 2: M N O P Q R Row 3: S T U V W X Row 4: Y Z (space) - . enter
When Sandy enters a waypoint description, the cursor always starts at A (position (0,0)). For each character in the phrase, the cursor is moved from its current cell to the cell containing that character. The cursor can only move horizontally or vertically and cannot move diagonally or outside the grid. The number of movements needed to move from one cell to another is the Manhattan distance between them. In other words, if the cursor moves from cell \((x_1,y_1)\) to cell \((x_2,y_2)\), the number of movements is given by:
After entering all characters of the phrase, the cursor must then be moved to the enter key (position (4,5)) to submit the description.
Your task is to calculate the total number of cursor movements needed to type in a given phrase on this grid.
inputFormat
The input consists of a single line, which is the waypoint description as a string. The string may contain uppercase letters, space, '-' or '.'.
outputFormat
Output a single integer representing the total number of cursor movements required to type the given phrase and then move to the enter key.
sample
GPS
15