Submit | All submissions | Best solutions | Back to list |
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.
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 |
hide comments
|
||||||||
2016-01-26 07:16:49
No match ----> No match. |
||||||||
2016-01-12 11:12:21 kartikay singh
any corner cases?? getting wa on testcase(5) [EDIT] : c++ users ..use char array , string class in C++ gave TLEs . Finally AC :-) Last edit: 2016-01-13 02:07:05 |
||||||||
2016-01-11 12:24:38
Can be done without trie as well, used C++ stl and strings with ios::sync_with_stdio(false) and cin.tie(0) in 0.38 :) |
||||||||
2015-12-17 14:53:48 Sarthak Taneja
My first problem on tries :D , ac in second go C++ String class and cin, cout cost me a tle :P... |
||||||||
2015-10-27 07:54:32 SUBHAJIT GORAI
use scanf and printf instead of cin and cout and char array instead of string .... |
||||||||
2015-10-27 06:11:36 [Mayank Pratap]
Why do some people post link to their solutions?? @Ankit Kumar:- Your blog claims to have 400+ solutions while you have solved only 160 problems.... :P |
||||||||
2015-10-20 13:36:09 [Mayank Pratap]
(Trie)d hard Got AC :) |
||||||||
2015-09-27 00:56:03 zain
TRIE recursion with fast I/O got AC Last edit: 2015-09-27 03:46:25 |
||||||||
2015-09-14 18:34:28 free mind ;)
Iterative trie solution accept while same thing i do with recursive giving WA :( |
||||||||
2015-07-20 21:55:55 Arun Vinud
Java NZEC :( Last edit: 2015-07-22 10:02:36 |