We all remember those childhood times when we learned how to use alphabet blocks to form different words, such as MOM, DAD, TRAIN, and others.
We propose you to remind this time for a while and imagine yourself being a child.
So, you have a set of alphabet blocks. There is a letter on each of the six faces of every block. Also, you have a
word associated with your childhood that you want to form.
Write a program that will verify if it is possible to form the necessary word out of the set. If yes, then
print "True" to stdout; otherwise, print "False".
You can choose only one letter from an alphabet block and place blocks in any order.
The first argument is a path to a file. Each line contains test cases that have three arguments separated by the pipe symbol "|".
1. The first argument in the line is a number that shows how many blocks are in the set.
2. The second one is a word that you want to form.
3. The third one is a list of arrays of letters. One face of the alphabet block includes one letter from array.
For example:
There is an array of letters "ABCDEF". It refers to one toy block with the following faces:
"A", "B", "C", "D", "E", "F".
4 | DOG | UPZRHR INOYLC KXDHNQ BAGMZI 6 | HAPPY | PKMFQP KTXGCV OSDMAJ SDSIMY OEPGLE JZCDHI 5 | PLAIN | BFUBZD XMQBNM IDXVCN JCOIAM OZYAYH
Print "True" to stdout if you can form the necessary word, or "False" if you cannot do this.
True True False
- The word length is from 4 to 18 characters.
- Number of blocks in the set is always equal to or greater than the word length.
- You can take only one block from the set to form one letter in the word.
- The letters in the word and letters on the faces of one block may repeat: the word might be "MOM" or there might be a block with "AAAAAA" faces.
- The number of test cases is 40.