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".
- If the string is of length 1 the trip length is 0.
- If the string is of length 2 or more then the trip length equals F plus R, where
- F is the the straight line distance between the centers of the keys corresponding to the first and second characters
- R is the length of the trip for the word with the first character removed.
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.
Doug Lea
Last modified: Sat Oct 16 08:10:13 EDT 1999