Word Ladder
Time limit1sMemory limit128 MB
Decide for each test case whether every consecutive word pair has equal length and differs in exactly one letter.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
A word ladder is a puzzle where you move from one word to the next by changing a single letter. Playing it takes both vocabulary and spelling, and checking an answer by hand is dull and easy to get wrong.
Two adjacent words form one rung of the ladder when both of these hold:
- the two words have the same length
- exactly one letter differs
Write a program that decides whether the given words form a ladder in the order they are written.
Input
The input holds several test cases. Each line has one word, and a line containing only # closes the current test case. Every word has 3 to 20 uppercase letters, and words inside one test case may have different lengths. After the # that closes the last test case, one more line with # marks the end of the input.
A test case with a single word has no pair to compare, so it forms a ladder.
Output
For each test case print Correct if the words form a ladder and Incorrect otherwise, one verdict per line.