UVA 123 Searching Quickly
来源:互联网 发布:怎么在爱淘宝上开店 编辑:程序博客网 时间:2024/05/21 15:44
Searching Quickly
Background
Searching and sorting are part of the theory and practice of computer science. For example, binary search provides a good example of an easy-to-understand algorithm with sub-linear complexity. Quicksort is an efficient [average case] comparison based sort.
KWIC-indexing is an indexing method 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 to write a program that generates a KWIC (Key Word In Context) index of the titles. In a KWIC-index, a title is listed once for each keyword that occurs in the title. The KWIC-index is alphabetized by keyword.
Any word that is not one of the ``words to ignore'' is a potential keyword.
For example, if words to ignore are ``the, of, and, as, a
'' and the list of titles is:
Descent of ManThe Ascent of ManThe Old Man and The SeaA Portrait of The Artist As a Young Man
A KWIC-index of these titles might be given by:
a portrait of the ARTIST as a young man the ASCENT of man DESCENT of man descent of MAN the ascent of 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 young man the old man and the SEA a portrait of the artist as a YOUNG man
The Input
The input is a sequence of lines, the string ::
is used to separate the list of words to ignore from the list of titles. Each of the words to ignore appears in lower-case letters on a line by itself and is no more than 10 characters in length. Each title appears on 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 15 words.
There will be no more than 50 words to ignore, no more than than 200 titles, and no more than 10,000 characters in the titles and words to ignore combined. No characters other than 'a'-'z', 'A'-'Z', and white space will appear in the input.
The Output
The output should be a KWIC-index of the titles, with each title appearing once for each keyword in the title, and with the KWIC-index alphabetized by keyword. If a word appears more than once in a title, each instance is a potential keyword.
The keyword should appear in all upper-case letters. All other words in a title should be in lower-case letters. Titles in the KWIC-index with the same keyword should appear in the same order as they appeared in the input file. In the case where multiple instances of a word are keywords in the same title, the keywords should be capitalized in left-to-right order.
Case (upper or lower) is irrelevant when determining if a word is to be ignored.
The titles in the KWIC-index need NOT be justified or aligned by keyword, all titles may be listed left-justified.
Sample Input
istheofandasabut::Descent of ManThe Ascent of ManThe Old Man and The SeaA Portrait of The Artist As a Young ManA Man is a Man but Bubblesort IS A DOG
Sample Output
a portrait of the ARTIST as a young man the ASCENT of man a man is a man but BUBBLESORT is a dog DESCENT of man a man is a man but bubblesort is a DOG descent of MAN the ascent of MAN the old MAN and the sea a portrait of the artist as a young MAN a MAN is a man but bubblesort is a dog a man is a MAN but bubblesort is a dog 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
题意:给定一些可以无视的单词。在给一些句子。如果句子中出现不可以无视的单词。就要输出这个句子。并且在关键词要变成大写。。注意:输出是要按关键词的字典序输出。。
思路:没什么好说的。。就是字符串处理。。我是用了STL 很方便。
把关键词和句子用pair绑定在一起。然后根据关键词来输出句子。。
#include<iostream>#include<string>#include<map>#include<set>#include<cstdio>#include<cctype>using namespace std;const int kMaxn = 205;const string kSign = "::";int main(){ set<string> ignore; string t; while (getline(cin,t) && t != kSign)ignore.insert(t); multimap<string,string> r; while (getline(cin,t)) {for (int i = 0; i < t.size(); i ++) t[i] = tolower(t[i]);for (int i = 0; i < t.size(); i ++){ if(!isalpha(t[i]))continue; int j = i; string t2; while (j < t.size() && isalpha(t[j])) {t2 += t[j];j ++; } if (ignore.find(t2) == ignore.end()) {for (int k = 0; k < t2.size(); k ++) t2[k] = toupper(t2[k]);string t3 = t;t3.replace(i,t2.size(),t2);r.insert(pair<string, string>(t2, t3)); } i = j;} } for(map<string,string> :: iterator i = r.begin();i != r.end();i ++)cout << i->second << endl; return 0;}
- UVa 123 Searching Quickly
- uva 123 Searching Quickly
- UVA 123 - Searching Quickly
- uva 123 - Searching Quickly
- uva-123 - Searching Quickly
- UVA 123 - Searching Quickly
- UVa 123 - Searching Quickly
- UVa 123 Searching Quickly
- uva 123 - Searching Quickly
- uva 123Searching Quickly
- UVA 123 Searching Quickly
- uva 123 - Searching Quickly
- uva - 123 - Searching Quickly
- UVa - 123 - Searching Quickly
- uva 123 Searching Quickly
- uva - 123 - Searching Quickly
- UVa 123 - Searching Quickly
- UVA 123 Searching Quickly
- UVA 10050 Hartals
- [leetcode] Longest Valid Parentheses
- 程序员,你当的了吗?——读《高效能程序员的修炼》有感
- HTTP 错误 500.21 - Internal Server Error 处理程序“PageHandlerFactory-ISAPI-4.0_32bit”在其模块
- 《iOS应用程序开发方法与实践》补充内容-2.13 再谈类的声明与实现
- UVA 123 Searching Quickly
- 权限系统设计思考
- const在c/c++中的区别
- C# CultureInfo列表详细说明
- HDU 2102 A计划(三维BFS)
- 在Mybatis-spring中由于默认Autowired导致不能配置多个数据源的问题分析及解决
- win7下安装sql sever2008无法重启和无法本地连接问题
- 关于递归效率问题
- UVA 10194 Football (aka Soccer)