博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 123 Searching Quickly
阅读量:6479 次
发布时间:2019-06-23

本文共 4437 字,大约阅读时间需要 14 分钟。

题意:给出一系列要忽略的单词,这些单词以外的单词都看作keyword。然后给出一些标题,找出标题中全部的keyword。然后按这些keyword的字典序给标题排序。

注意两点:同样keyword出如今不同标题中,出如今输入较前位置的标题排在前面(从例子数据能够看出,并且multimap也正是这么做的);同一个keyword在一个标题中出现多次,keyword位于较前位置的排在前面(从左向右扫描的话就没有问题)。

ACM Contest Problems Archive University of Valladolid (SPAIN)

123 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 ecient O(n log n) [average case] comparison based sort.
KWIC-indexing is an indexing method that permits ecient \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 Man
The Ascent of Man
The Old Man and The Sea
A 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.ACM Contest Problems Archive University of Valladolid (SPAIN)
The keyword should appear in all upper-case letters. All other words in a title should be in lowercase letters. Titles in the KWIC-index with the same keyword should appear in the same order as they
appeared in the input le. 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 justi ed or aligned by keyword, all titles may be listed
left-justi ed.
Sample Input
is
the
of
and
as
a
but
::
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
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

#include
#include
#include
#include
char ignore[55][15],title[205][1005],keywords[1001][105];int num[1001];#define strlen (int)strlenint find1(int n,char *s){ for(int i=0;i
='A'&&title[f][i]<='Z')title[f][i]+='a'-'A'; if(isalpha(title[f][i]))ch[c++]=title[f][i]; else { ch[c]='\0'; c=0; if(find1(n,ch))memcpy(keywords[n2++],ch,sizeof(ch)); } } } qsort(keywords,n2,sizeof(keywords[0]),cmp); memset(num,0,sizeof(num)); for(int i=0;i
num[i])break; } } } return 0;}

转载地址:http://sxgko.baihongyu.com/

你可能感兴趣的文章
IT人员的职业生涯规划
查看>>
sorry,you must have a tty to run sudo
查看>>
ios开发中使用正则表达式识别处理字符串中的URL
查看>>
项目中的积累,及常见小问题
查看>>
Python类型转换、数值操作(收藏)
查看>>
oracle11g dataguard 安装手册(转)
查看>>
java并发包分析之———Deque和LinkedBlockingDeque
查看>>
1. Two Sum - Easy - Leetcode解题报告
查看>>
多线程---同步函数的锁是this(转载)
查看>>
鱼C记事本V1.0(下)- 零基础入门学习Delphi28
查看>>
百练 2742 统计字符数 解题报告
查看>>
Ubuntu搜狗输入法候选词乱码
查看>>
js中回调函数写法
查看>>
React native android 最常见的10个问题
查看>>
数据结构和算法
查看>>
.Net 项目代码风格要求
查看>>
[pat]1045 Favorite Color Stripe
查看>>
Immutable学习及 React 中的实践
查看>>
【转】性能测试步骤
查看>>
OSI与TCP/IP各层的结构与功能,都有哪些协议
查看>>