首页 > 其他分享 >uva 123(排序、检索)

uva 123(排序、检索)

时间:2023-06-28 19:32:36浏览次数:40  
标签:检索 titles Man temp title 123 uva MAN man


题目:

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.

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

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.

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

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

题解:::之前的都是要忽略的单词 ,在后面的句子里出了可忽略的单词外都是关键字,将所有关键字找出,用map将关键字和他所在的句子关联起来,并将其关联的句子输出,对应关键字大写其他单词小写,有相同关键字就按输入顺序输出。

#include <iostream>
#include <cstdio>
#include <map>//按key值自动从小到大排序
#include <set>
#include <string>
using namespace std;

string key[55], title[205], temp, temp1;
multimap <string, string> p;//可存储重复的key
set<string> s;
int main() {
	int n = 0, m = 0;
	while (getline(cin, key[n])) {
		if (key[n][0] == ':' && key[n][1] == ':')
			break;
		else {
			s.insert(key[n]);
			n++;
		}
	}
	while (getline(cin, title[m])) {
		temp = temp1 = "";
		int len = title[m].size();
		for (int i = 0; i < len; i++)
			title[m][i] = tolower(title[m][i]);
		for (int i = 0; i < len + 1; i++)
			if (isalpha(title[m][i]))//如果是字母
				temp += title[m][i];
			else {
				if (s.count(temp) == 0) {//set.count(temp)可得到temp在set集合中出现的次数
					for (int k = 0; k < temp.size(); k++)
						temp[k] = toupper(temp[k]);//关键字转成大写
					temp1 = title[m];
					temp1.replace(i - temp.size(), temp.size(), temp);//string.replace(起始位置,替换长度,用于替换的string)
					p.insert(pair<string, string>(temp, temp1));//map的插入语句
					temp1 = title[m];
				}
				temp = "";
			}
		m++;
	}
	multimap <string, string>::iterator it = p.begin();//定义map的迭代器并赋初始值
	for (; it != p.end(); it++)
		cout << it->second << endl;
	return 0;
}




标签:检索,titles,Man,temp,title,123,uva,MAN,man
From: https://blog.51cto.com/u_10729926/6575700

相关文章

  • uva 10034(最小生成树)
    题目:InanepisodeoftheDickVanDykeshow,littleRichieconnectsthefrecklesonhisDad'sbacktoformapictureoftheLibertyBell.Alas,oneofthefrecklesturnsouttobeascar,sohisRipley'sengagementfallsthrough.ConsiderDick......
  • uva 10878(字符串)
    题目:"Machinestakemebysurprisewithgreatfrequency."AlanTuringYourbosshasjustunearthedarollofoldcomputertapes.Thetapeshaveholesinthemandmightcontainsomesortofusefulinformation.Itfallstoyoutofigureoutwhatisw......
  • uva 113(数学)
    题目:Currentworkincryptographyinvolves(amongotherthings)largeprimenumbersandcomputingpowersofnumbersmodulofunctionsoftheseprimes.Workinthisareahasresultedinthepracticaluseofresultsfromnumbertheoryandotherbranchesofmat......
  • 谷粒商城项目篇10_分布式高级篇_ES首页检索功能、异步、商品详情
    目录首页检索功能异步商品详情一、首页检索功能1.环境准备配置本地域名解析配置nginx将请求转给网关http{includemime.types;default_typeapplication/octet-stream;sendfileon;keepalive_timeout65; #配置上游服务器(网关) u......
  • GCM155R71H123JA55D 电容器芯片
    GCM155R71H123JA55D是一种电容器芯片,属于电子元器件中的passives类型。电容器芯片是一种能够存储电荷和电能的元器件,通常使用于电路中起到储存、隔离和滤波作用。GCM155R71H123JA55D电容器芯片的电容值为12nF,电压等级为50V,其特点包括高压容比、无极性、体积小等。它采用陶瓷材料......
  • Authentication to host '10.167.32.123' for user 'root' using method 'mysql_
    连接Mysql5.7以上的版本的数据库出现报错:C#连接远程连接mysql时,抛异常:Authenticationtohost'10.167.32.123'foruser'root'usingmethod'mysql_native_password'failedwithmessage:Readingfromthestreamhasfailed最终在Mysql官网的bug提交区发现已经有人也遇到......
  • 8万中医药方剂数据库检索方剂大全ACCESS\EXCEL数据库
    今天这一份方剂数据库是最全也是最好的方剂数据库,不但字段内容多,而且记录数也是最多的,字段包含:名称、组成、出处、功效、主治、加减、用法用量、制备方法、临床应用、各家论述、用药禁忌、附注等。HTML内容字段是排版好了的全部内容截图下方有显示“共有记录数”,截图包含了表的所有......
  • 自然语言处理 Paddle NLP - 检索式文本问答-理论
    问答系统(QuestionAnsweringSystem,QA)是信息检索系统的一种高级形式,它能用准确、简洁的自然语言回答用户用自然语言提出的问题。其研究兴起的主要原因是人们对快速、准确地获取信息的需求。问答系统是人工智能.抽取式阅读理解:它的答案一定是段落里的一个片段,所以在训练前,先要......
  • UVA12222 Mountain Road 山路 题解 dp
    UVA12222山路题意:--一个山路只有一条车道,因此不能有两辆方向相反的车同时在车道内。同时,为了保证安全,车道内不能超车,且同向行驶的车间距必须大于10分钟。现在给你n辆车,三个参数依次表示行驶方向,到达时刻,行驶时间。问如何安排能使最后一个通过的车通过时的时刻最小,输出这个值......
  • UVA11090 Going in Cycle!!题解
    题目大意给定一个N个点M条边的带权有向图,求平均值最小的回路。解法看到这种题目,喜欢打暴力的我一下就想到:遍历整个图,找到每一个环,然后算出它们的平均值,最后比较出最小值。然而,呃...,会T飞...既然我们不能暴力找最小值,那还有什么别的办法吗?我们只需要输出一个最小值就行了,既然......