Problem E
Gandalf's Spell

Today, Gandalf woke up from an awful dream that told him that the hobbit needs to be mentally prepared for the journey ahead. So, Gandalf decided to create a spell where it would replace every unique word in a sentence with a unique character. However, Gandalf is cheeky so he decided to test the hobbit by seeing whether he can check if this one-to-one mapping from word to character was satisfied given a string of characters and a sentence string. Your job is to put yourself in the position of the hobbit, and write the code so that it displays “True” if every character in the string maps to words in the sentence in the same order, with every unique character consistently mapping to the same unique word and every unique word consistently mapping to the same unique character. Otherwise, display “False”. Do you think you got what it takes to be the next Hobbit?


Input consists of two strings. The first line will contain the string of alphanumeric characters which will have from $1$ to $100$ characters. Then, the second line will contain the sentence string, where every word in the sentence will be space-separated, and the words can only contain alphanumeric characters. The sentence will have from $1$ to $100$ words and from $1$ to $500$ total characters.


Display “True” if each character from the string of characters maps one-to-one to a unique word in the sentence string, and that this mapping is in the same order. Otherwise, display “False”.

Sample Input 1 Sample Output 1
why they they
Sample Input 2 Sample Output 2
CCPC is the best CCPC is the best
Sample Input 3 Sample Output 3
The quick brown fox jumps over the lazy dog

Please log in to submit a solution to this problem

Log in