0% found this document useful (0 votes)
21 views2 pages

429 Word Transformation: Input and Output

This document describes a word transformation puzzle where words are changed one letter at a time to transform an initial word into a target word. Contestants must write a program that takes as input a dictionary of words and starting/ending word pairs, and outputs the minimum number of steps needed to transform each starting word into its corresponding ending word. The input contains the dictionary followed by word pairs, and the output lists each pair with the starting word, ending word, and minimum step count separated by spaces.

Uploaded by

yassine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

429 Word Transformation: Input and Output

This document describes a word transformation puzzle where words are changed one letter at a time to transform an initial word into a target word. Contestants must write a program that takes as input a dictionary of words and starting/ending word pairs, and outputs the minimum number of steps needed to transform each starting word into its corresponding ending word. The input contains the dictionary followed by word pairs, and the output lists each pair with the starting word, ending word, and minimum step count separated by spaces.

Uploaded by

yassine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ACM Contest Problems Archive

University of Valladolid (SPAIN)

429 Word Transformation


A common word puzzle found in many newspapers and magazines is the word transformation. By taking
a starting word and successively altering a single letter to make a new word, one can build a sequence
of words which changes the original word to a given end word. For instance, the word \spice" can
be transformed in four steps to the word \stock" according to the following sequence: spice, slice,
slick, stick, stock. Each successive word di ers from the previous word in only a single character
position while the word length remains the same.
Given a dictionary of words from which to make transformations, plus a list of starting and ending
words, your team is to write a program to determine the number of steps in the shortest possible
transformation.

Input and Output

The input will be a single le in two sections. The rst section will be the dictionary of available words
with one word per line, terminated by a line containing an asterisk (*) rather than a word. There can
be up to 200 words in the dictionary; all words will be alphabetic and in lower case, and no word will
be longer than ten characters. Words can appear in the dictionary in any order.
Following the dictionary are pairs of words, one pair per line, with the words in the pair separated
by a single space. These pairs represent the starting and ending words in a transformation. The pairs
are terminated by the end-of- le. All pairs are guaranteed to have a transformation using the dictionary
given. The starting and ending words will appear in the dictionary.
The output should contain one line per word pair, and must include the starting word, the ending
word, and the number of steps in the shortest possible transformation, separated by single spaces.

Sample Input
dip
lip
mad
map
maple
may
pad
pip
pod
pop
sap
sip
slice
slick
spice
stick
stock
*
spice stock
may pod

ACM Contest Problems Archive

Sample Output
spice stock 4
may pod 3

University of Valladolid (SPAIN)

You might also like