Problem Classification
InterviewTime limit1sMemory limit512 MB
Count exact whole-word occurrences of each category's keywords in a statement, then print the categories with the highest total count in lexicographic order.
- Level
Medium4 of 10
- Topics
- Hash map, String, Implementation, Sorting
- Solved
- No attempts yet
Problem
When reading programming problems, one can often get hints about the topic of a problem by skimming the problem statement for certain words. If, for example, the word "vertex" or "edge" appears, the problem is almost certainly a graph problem, while the words "words" or "letters" suggest that the problem is about strings.
Your task is to implement a simple program that attempts to classify a problem according to one of categories. Each category has an associated set of words, which, if they appear as words in a statement, suggest the problem belongs to this category. When classifying a statement, the program should suggest those categories which have the highest number of occurrences of their associated words. Note that words that are part of other words do not count. For example, the word statement should not count as an occurrence for the word ate.
In the above example, we suggested that the category graph may have the associated words vertex and edge and the category string could have the associated words words and letters. Then, if there were occurrences each of the words vertex and edge, the number of matches for the category graph would be . If the statement contained occurrences of words and of letters, the number of matches for the category string would be . Since there are more matches for the second category, the program should suggest it.
If there are multiple categories with the same number of matches, your program should suggest all of them.
Input
The first line of input contains the number of categories .
The next lines each contain a description of a category. The description starts with the name of the category, a single word. Then, an integer follows, which is the number of words associated with this category. This is followed by those words, separated by spaces. No two words within a category are the same, and no two categories have the same name.
This is followed by a number of lines describing the statement of the problem. Each line contains a list of space-separated words.
Every word in the input will consist solely of at most lower-case letters a-z. The statement consists of between and words.
Output
For each suggested category, output the name of the category on a single line, in lexicographical order.