A number can be transformed to another number if the letters in the digits of the first number are the same as those in the second number with at most 5 letters (in total) being added or deleted. Individual digits are spelt ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE and ZERO. For example: • 61 can be transformed to 26 since the letters SIXONE, with 4 changes (N and E deleted, and T and W added), can then be arranged to TWOSIX. Note that the order of the letters does not matter. A number ladder is a sequence of transformations that changes one number to a different number. Between any two adjacent numbers on the ladder a valid transformation takes place. No number appears more than once on a ladder. The size of a ladder is the number of transformations that takes place. For example: • 1, 90, 610 is a number ladder (of size 2) since 1 can be transformed to 90 and 90 can be transformed to 610. There is no smaller number ladder that starts with 1 and finishes with 610 since 1 cannot be transformed to 610. Write a program to determine the size of smallest number ladders. Sample run Your program should read in three lines, each containing two integers s then f, (1 " s < f " 999). You should output three numbers (one per line), the ith of which giving the size of the smallest number ladder (that only uses numbers between 1 and 999 inclusive) going from s to f on the ith line of the input. |
input: 250 361 34 756 18 735 output: 3 4 3 |
77 383 48 677 232 471 |
|
|