F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Keywords

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 229    Accepted Submission(s): 13


Problem Description
Many researchers are faced with an ever increasing number of journal articles to read and find it difficult to locate papers of relevance to their particular lines of research. However, it is possible to subscribe to various services which claim that they will find articles that fit an `interest profile' that you supply, and pass them on to you. One simple way of performing such a search is to determine whether a pair of keywords occurs `sufficiently' close to each other in the title of an article. The threshold is determined by the researchers themselves, and refers to the number of words that may occur between the pair of keywords. Thus an archeologist interested in cave paintings could specify her profile as ``0 rock art'', meaning that she wants all titles in which the words ``rock'' and ``art'' appear with 0 words in between, that is next to each other. This would select not only ``Rock Art of the Maori'' but also ``Pop Art, Rock, and the Art of Hang-glider Maintenance''.


Write a program that will read in a series of profiles followed by a series of titles and determine which of the titles (if any) are selected by each of the profiles. A title is selected by a profile if at least one pair of keywords from the profile is found in the title, separated by no more than the given threshold. For the purposes of this program, a word is a sequence of letters, preceded by one or more blanks and terminated by a blank or the end of line marker.

 

Input
Input will consist of no more than 50 profiles followed by no more than 250 titles. Each profile and title will be numbered in the order of their appearance, starting from 1, although the numbers will not appear in the file.


Each profile will start with the characters ``P:'', and will consist of a number representing a threshold, followed by two or more keywords in lower case.
Each title will start with the characters ``T:'', and will consist of a string of characters terminated by ``|''. The character ``|'' will not occur anywhere in a title except at the end. No title will be longer than 255 characters, and if necessary it will flow on to more than one line. No line will be longer than eighty characters and each continuation line of a title will start with at least one blank. Line breaks will only occur between words.

All non-alphabetic characters are to be ignored, thus the title ``Don't Rock -- the Boat as Metaphor in 1984'' would be treated as ``Dont Rock the Boat as Metaphor in'' and ``HP2100X'' will be treated as ``HPX''. The file will be terminated by a line consisting of a single #.

 

Output
Output will consist of a series of lines, one for each profile in the input. Each line will consist of the profile number (the number of its appearance in the input) followed by ``:'' and the numbers of the selected titles in numerical order, separated by commas and with no spaces.
 

Sample Input
P:[bk]0[bk]rock[bk]art P:[bk]3[bk]concepts[bk]conceptions P:[bk]1[bk][bk][bk]art[bk]rock[bk][bk][bk]metaphor[bk]concepts T:[bk]Rock[bk]Art[bk]of[bk]the[bk]Maori| T:[bk]Jazz[bk]and[bk]Rock[bk]-[bk]Art[bk]Brubeck[bk]and[bk]Elvis[bk]Presley| T:[bk]Don't[bk]Rock[bk]---[bk]the[bk]Boat[bk]as[bk]Metaphor[bk]in[bk]1984,[bk]Concepts [bk][bk][bk]and[bk](Mis)-Conceptions[bk]of[bk]an[bk]Art[bk]Historian.| T:[bk]Carved[bk]in[bk]Rock,[bk]The[bk]Art[bk]and[bk]Craft[bk]of[bk]making[bk]promises [bk][bk][bk]believable[bk]when[bk]your[bk]`phone[bk]bills[bk]have[bk]gone [bk][bk][bk]through[bk]the[bk]roof| #
 

Sample Output
1:[bk]1,2 2:[bk] 3:[bk]1,2,3,4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 01:53:06, Gzip enabled