TOJ 2028.Excuses, Excuses!(字符串)-程序员宅基地

技术标签: Toj水题  水题  toj  

题目链接:http://acm.tju.edu.cn/toj/showp2028.html


2028.    Excuses, Excuses!
Time Limit: 0.5 Seconds    Memory Limit: 65536K
Total Runs: 288    Accepted Runs: 115



Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listening to goofy excuses, Judge Ito has asked that you write a program that will search for a list of keywords in a list of excuses identifying lame excuses. Keywords can be matched in an excuse regardless of case.

Input

Input to your program will consist of multiple sets of data. Line 1 of each set will contain exactly two integers. The first number (1 ≤ K ≤ 20) defines the number of keywords to be used in the search. The second number (1 ≤ E ≤ 20) defines the number of excuses in the set to be searched. Lines 2 through K+1 each contain exactly one keyword. Lines K+2 through K+1+E each contain exactly one excuse. All keywords in the keyword list will contain only contiguous lower case alphabetic characters of length L (1 ≤ L ≤ 20) and will occupy columns 1 through L in the input line. All excuses can contain any upper or lower case alphanumeric character, a space, or any of the following punctuation marks [".,!?] not including the square brackets and will not exceed 70 characters in length. Excuses will contain at least 1 non-space character.

Output

For each input set, you are to print the worst excuse(s) from the list. The worst excuse(s) is/are defined as the excuse(s) which contains the largest number of incidences of keywords. If a keyword occurs more than once in an excuse, each occurrance is considered a separate incidence. A keyword "occurs" in an excuse if and only if it exists in the string in contiguous form and is delimited by the beginning or end of the line or any non-alphabetic character or a space.

For each set of input, you are to print a single line with the number of the set immediately after the string "Excuse Set #". (See the Sample Output). The following line(s) is/are to contain the worst excuse(s) one per line exactly as read in. If there is more than one worst excuse, you may print them in the input's order. After each set of output, you should print a blank line.

Sample Input

5 3
dog
ate
homework
canary
died
My dog ate my homework.
Can you believe my dog died after eating my canary... AND MY HOMEWORK?
This excuse is so good that it contain 0 keywords.
6 5
superhighway
crazy
thermonuclear
bedroom
war
building
I am having a superhighway built in my bedroom.
I am actually crazy.
1234567890.....,,,,,0987654321?????!!!!!!
There was a thermonuclear war!
I ate my dog, my canary, and my homework ... note outdated keywords?

Sample Output

Excuse Set #1
Can you believe my dog died after eating my canary... AND MY HOMEWORK?

Excuse Set #2
I am having a superhighway built in my bedroom.
There was a thermonuclear war!



Source: South Central USA 1996
Submit   List    Runs   Forum   Statistics

一道字符串匹配的题,就是输出与key数组匹配最多的串,注意串不知一个!

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string> 

using namespace std;
struct Node{
	char str[201];
	int num;
}Word[31];
int main(){
	int n,t;
	char key[31][31];
	char str[201];
	int flag=1;
	while(~scanf("%d %d",&n,&t)){
		
		int Maxn=-1;
		for(int i=0;i<n;i++)
			scanf("%s",key[i]);
		getchar();
		//printf("%s\n",key[4]);
		for(int i=1;i<=t;i++){
			Word[i].num=0;
			gets(str);
			//printf("%s\n",str);
			int len=strlen(str);
			char tmp[201];
			strcpy(tmp,str);
			strcpy(Word[i].str,str);
			//printf("%s\n",tmp);
			for(int j=0;j<len;j++)
				if(tmp[j]>='A'&&tmp[j]<='Z')
					tmp[j]=tmp[j]-'A'+'a';
			string s(tmp);
			for(int j=0;j<n;j++){
				int sat=0;
				while(1){
					sat=s.find(key[j],sat);
					if(sat==-1)
						break;
					if(sat>=1)
						if((tmp[sat-1]<'a'||tmp[sat-1]>'z')&&(tmp[sat+strlen(key[j])]<'a'||tmp[sat+strlen(key[j])]>'z'))
							Word[i].num++;
					sat++;
				}
				if(Maxn<Word[i].num)
					Maxn=Word[i].num;
			}
		}
		printf("Excuse Set #%d\n",flag++);
		for(int i=1;i<=t;i++)
			if(Word[i].num==Maxn)
				printf("%s\n",Word[i].str);
		printf("\n");
	}
} 


版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/muyujinxi/article/details/52374001

智能推荐

jenkins构建并远程发布后执行shell脚本_jenkins 执行shell脚本复制文件-程序员宅基地

文章浏览阅读2.2w次,点赞2次,收藏3次。由于jenkins远程发布war文件到不同环境下的tomcat下时,会先删除同名文件后再进行远程拷贝,此时保留在本地的配置文件需收到copy。 为实现自动化发布,特在发布后执行shell脚本,远程copy,同时重启tomcat解决步骤: 1: 2:脚本配置#!/bin/sh#datetime: 2015-3-3 17:00#autho_jenkins 执行shell脚本复制文件

pso_pso-bp讲解csdn-程序员宅基地

文章浏览阅读2.1k次。微粒群算法(Paticle swarm optimization PSO)源码和程序下载地址2007-04-21 21:29 ProgramsLast checkParticle Swarm OptimizerBibliography Researchers Conferences Link to_pso-bp讲解csdn

2023年6月杭州/广州/深圳NPDP产品经理认证招生简章-程序员宅基地

文章浏览阅读516次。产品开发与管理协会(PDMA)成立于1979年,是全球范围内产品开发与管理专业人士最杰出的倡导者,协助个人、企业或组织提升其产品开发与管理的能力与成效。产品经理国际资格认证NPDP是新产品开发方面的认证,集理论、方法与实践为一体的全方位的知识体系,为公司组织层级进行规划、决策、执行提供良好的方法体系支撑。提升工作能力:NPDP方法是执行创新的最佳实战,让您迅速获得全球产品开发领域积累的正确原则、方法、流程、模板和工具,使您成为这一领域的专家和领导者。■ 产品生命周期管理与产品退市管理。

QTime中currentTime()的使用方法-程序员宅基地

文章浏览阅读520次。QTime中currentTime()的使用方法QTime是Qt中一个处理时间的类,其成员函数currentTime()是最经常用到函数,下面举例说明该成员函数如何使用。 1. 包含头文件 #include &lt;QTime&gt; 2. 声明一个QTime对象 QTime qtimeObj; 3. 利用currentTime()获取当前时间 ..._qtime::currenttime

C&C++结构实训(国防科大)_第1关:有理数化简-程序员宅基地

文章浏览阅读1.7w次,点赞37次,收藏146次。最后一个借鉴大佬代码,不太熟悉结构函数,需要练熟,c++_第1关:有理数化简

求两个球的体积并_求球的体积并-程序员宅基地

文章浏览阅读1.2k次。两个球和两个圆一样,有三种情况。相交,分离(包括两种情况)对于分离的两种情况,好计算。但是对于相交的情况,不好计算。需要计算球冠的大小。就是这样。昨天晚上牛客上有一个关于这样的题代码如下:#include&lt;bits/stdc++.h&gt;using namespace std;const double PI = acos(-1.0);double x1,y11,z1,r1;..._求球的体积并

随便推点

关于CRISPR基因编辑防脱靶、高效编辑的一种方法学评估_pam序列-程序员宅基地

文章浏览阅读2.9k次。CRISPR是ClusteredRegularlyInterspacedShortPalindromicRepeats的缩写,中文意思为规律间隔成簇短回文重复序列。在自然界中,CRISPR在细菌的免疫系统中起到非常重要的作用。当病毒入侵细菌时,细菌中的分子机制会将病毒的部分序列插入到CRISPR位点中。当病毒再次入侵时,CRISPR位点会进行转录和加工。加工后的CRISPR RNA会与Cas蛋白形成核糖核蛋白复合物,对病毒的基因组进行“扫描”。当发现与CRISPR RNA互补配对的片段后便..._pam序列

GTC 火山引擎线上专场 | 解码字节跳动多场景技术内核及应用-程序员宅基地

文章浏览阅读1.2w次,点赞2次,收藏2次。活动简介12 月 19 日,GTC 智能增长技术专场,火山引擎将以「智能增长」为主题,为大家带来字节跳动在机器学习领域沉淀的技术经验,智能平台、数据智能、语音识别、联邦学习等场景的前沿应..._字节跳动的核心在于推荐算法,你认为它基于这一核心还可以连接哪些场景?

mac unzip Illegal byte sequence_unzip checkdir error illegal byte sequence-程序员宅基地

文章浏览阅读2.6k次,点赞2次,收藏3次。mac unzip Illegal byte sequence_unzip checkdir error illegal byte sequence

Yii里文件上传的操作方法(图片修改,在详情上展示,批量上传待续...)-程序员宅基地

文章浏览阅读79次。$model->img= UploadedFile::getInstance($model,'img');if ($model->validate()) {//$model->img->saveAs('uploads/'.$model->img->baseName.'.'.$model->img->extension);$model->..._yii1.1多图上传

ECharts - 极坐标系下的堆叠柱状图_极坐标系下的堆叠柱状图 位置-程序员宅基地

文章浏览阅读7.6k次。极坐标系下的堆叠柱状图链接:https://pan.baidu.com/s/1tSSDIPOmK9J6lXICJC3N1w提取码:0ggb_极坐标系下的堆叠柱状图 位置

【Docker】手把手教你使用Docker安装kafka【详细教程】_docker kafka-程序员宅基地

文章浏览阅读1.2w次,点赞22次,收藏88次。手把手教你使用Docker安装kafka_docker kafka