PROB4: TELEPHONE ALPHABETICS

A telephone set has 12 buttons, as shown in the figure below (and some additional buttons, which are not relevant to this problem). On certain occasions (for example, when the user wishes to add a new name to the private phone directory stored in the telephone set) the telephone set is in alphabetical entry mode. In alphabetical entry mode, the user can enter a certain letter by pressing the corresponding digit key as many times as the position (in left-to-right order) of the desired letter on that particular key. For example, pressing the key 7 once means a 'P', whereas pressing the same key four times means an 'S'. The # key is used to separate successive letters. However, as shown by the examples to be given, pressing the # key between two letters may be omitted when it is clear where one letter ends and the next one begins. An example input, in prob4.dat, is With this example input, your program should create a file prob4.out with the following contents: