Problem three:
Telephone Tours

A telephone word is simply any string of letters (a..z,A..Z) and digits (0..9). Your program will read a telephone word and compute and print the "telephone tour length" corresponding to the given string. The length of the "telephone tour" for a given "telephone word" is defined by the following "button traversing procedure".
  1. If the string is of length 1 the trip length is 0.

  2. If the string is of length 2 or more then the trip length equals F plus R, where
For example (rounding answers to 3 decimals):
word       distance
 abc        2.125
 xyz        0.000
 ACM        5.130
 R2D2       4.250
 Oswego    17.846
 telephone 25.760
The telephone has buttons layed out in the form of a 4-row by 3-column grid as suggested by the following diagram. Each button is a square of side 1.5 units. Moreover, the distance between adjacent buttons, in both the horizontal and vertical directions, is 0.625 units.

A
1
BCD
2
E
3
FGH
4
I
5
JKLMN
6
O
7
PQRST
8
U
9
VWXYZ
0
Doug Lea
Last modified: Sat Oct 16 08:10:13 EDT 1999