DICT - Search in the dictionary!
Eloy the byte is helping his son, Marcos the little one, with the homework, which consists on: Given one or more words you should search in the dictionary which word contains the proper prefix of the word given, for example 'set' is a prefix of 'setter', but also of 'setting'.
Now, neither Eloy nor Marcos wants to search the words in the dictionary (they just won’t do it.) Marcos will give you the words in the dictionary and the words to find the prefix of. You should make a program that given this, output the list of words that contains as a prefix the word given, Marcos can make mistakes sometimes, so, be careful! Marcos won’t always be telling the real prefixes all the time, in addition, sometimes Marcos can repeat the same word (while reading the dictionary), in this case, the word should be treated as it was mentioned just one time.
Input
The input will consist in an integer N (1 <= N <= 25.000), next, N lines will follow containing a single word (maximum of 20 characters (all lowercase letters)), after that, there will be an integer K (1 <= K <= 22.000) containing the number of words to look in the dictionary, then, K lines containing the prefix-word.
Output
The output will consist in displaying the words that are composed from the word given, you should output “Case #i:” where i is the i-th case, then, at the next line, output the list of the composed words (lexicographical-ordered), if there is none, you should output “No match.”
Sample
Input: 5 set lol setter setting settings 2 set happy Output: Case #1: setter setting settings Case #2: No match.
hide comments
Matja¾:
2015-06-27 23:40:16
I think this problem should be improved - there are various sentences that could be made clearer. Also it's clear that it is possible construct a case where essentially any solution will run out of time. |
|
Anubhav Gupta:
2015-05-20 10:11:02
getting tle after 5th test case. i'm using tries |
|
Vipul Srivastava:
2015-04-19 13:51:48
Can someone point out the expected complexity to get AC in this problem? Last edit: 2015-04-19 13:52:33 |
|
Anuva Agarwal:
2015-01-17 11:03:29
n is 25000 and not 25. Likewise for k. |
|
Jumpy:
2014-12-07 16:39:49
GUYS!!! PLEASE BE CAREFUL that 2nd output, it is "No match." not "No match" only. Last edit: 2014-12-07 16:40:14 |
|
Archit Jain:
2014-10-18 18:45:41
awesome problem |
|
Cosmin Rusu:
2014-03-19 10:28:16
Nice problem, got AC from the first submission. Regarding the question about the empty line between the test cases, NO, you don't need to print a new line between cases. |
|
Srihari Madabusi:
2013-09-04 20:34:11
Are there 1 or two spaces between the input and the output?because there are two in the Sample data. |
|
Meryovi:
2012-07-01 03:33:58
There's a discrepancy between the suggested input and the example. What's the right one? |
|
:D:
2012-05-28 00:46:01
It simply means that some prefixes will result in "No match" scenario. |
Added by: | david_8k |
Date: | 2012-01-12 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Own problem |