123-searching Quickly
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem &problem=59
Background
Searching and sorting are part of the theory and practice of computer. For example, binary search provides a good example of the Easy-to-understand algorithm with sub-linear complexity. Quicksort is a efficient [average case] comparison based sort.
Kwic-indexing is a indexing how that permits efficient ' human search ' of, for example, a list of titles.
The Problem
Given a list of titles and a list of "words to ignore", you are are to write a program this generates a KWIC (Key Word in Co ntext) index of the titles. In a Kwic-index, a title was listed once for all keyword that occurs in the title. The kwic-index is alphabetized by keyword.
Any word "isn't" one of the ' words to ignore ' is a potential keyword.
For example, if words to ignore are ', of, and, as, a ' and the ' list of titles are:
Descent of Man, the Ascent of Man, and the sea
a portrait of the
Artist as
a
A Kwic-index of these titles might is given by:
A portrait of the ARTIST as a young man the ASCENT of "descent of Man" descent of Man the
ASCENT of
man< C5/>the old man and the sea a portrait of the artist as a young man, the old man and the Sea
a portrait of the Artist as a young man, the old man, and the sea
a portrait of the artist as a
The Input
The input is a sequence of lines, the string:: are used to separate the list of words to ignore from the list of titles. Each of the words to ignore appears into lower-case letters on "a" by itself and are no more than in length. Each title appears in a line by itself and may consist of mixed-case (upper and lower) letters. Words in a title are separated by whitespace. No title contains more than words.
There'll be no. than words to ignore, no more than than titles, and No. than 10,000 in the characters Les and words to ignore combined. No characters other than ' a '-' Z ', ' a '-' Z ', and white spaces would appear in the input.
The Output
The output should be a kwic-index to the titles with each title appearing once for each keyword in the title, and with th e kwic-index alphabetized by keyword. If A word appears more than once in a title, the instance is a potential keyword.
The keyword should appear in all upper-case letters. All other words in a title should is in lower-case letters. Titles in the kwic-index with the same keyword should appear, the same order as they the input file. In the case where multiple instances of a word are keywords in the same title, the keywords should is capitalized in left- To-right order.
Case (upper or lower) was irrelevant when determining if a word was to be ignored.
The titles in the Kwic-index need is justified or aligned by keyword, and all titles are listed left-justified.