Question: Please answer in C++ Suppose that you are given a set of words; and two words from the set: word 1 and word 2. Write
Please answer in C++ Suppose that you are given a set of words; and two words from the set: word 1 and word 2.
Write a program which will transform word 1 into word 2 by changing a single letter in word 1 at a time.
Every transition that word 1 takes will have to be in the set of words.
You must output the smallest sequence of transitions possible to convert word 1 into word 2.
You may assume that all the words in the dictionary are the same length.
The first line will be word 1 and word 2 separated by a comma, followed by the set of words. The set of words will be terminated by a -1.
Input:
DOG,GOD
DOG
BOG
GOG
ABH
GOD
THU
IOP
-1
Output:
DOG -> GOG -> GOD
Input:
HOUSE,JOUKS
MOUSE
HIUKE
HIUKS
HOUSH
LOUSE
HOZKS
SOUSE
HOUKS
HOUSE
HOUKE
JOUKZ
JOUKS
HOIKE
-1
Output:
HOUSE -> HOUKE -> HOUKS -> JOUKS
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
