UVa 409 Excuses, Excuses! (字符串匹配)

409 - Excuses, Excuses!

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=350

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 ( ) defines the number of keywords to be used in the search. The second number ( ) 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 ( ) 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 [SPMamp".,!?&] 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 any 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 #1Can you believe my dog died after eating my canary... AND MY HOMEWORK?Excuse Set #2I am having a superhighway built in my bedroom.There was a thermonuclear war!

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索number
, y97 ate icker
, date 集成 ate
, contain
, in
, lame
, lame编码器
, of
, The
, Crazy
keywords
uva 409、字符串匹配、正则表达式匹配字符串、js 匹配字符串、python 字符串匹配,以便于您获取更多的相关知识。

时间: 2024-12-14 06:47:42

UVa 409 Excuses, Excuses! (字符串匹配)的相关文章

UVa 401 Palindromes:字符串匹配

401 - Palindromes Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342 A regular palindrome is a string of numbers or letters that is the same forward as b

UVA之409 - Excuses, Excuses!

 Excuses, Excuses!  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

c-文件中字符串匹配问题

问题描述 文件中字符串匹配问题 判断文件中是否存在某一字符串,若存在则退出,若不存在则添加???求用c编写的代码,,,各位大虾帮帮忙,万分感谢!!!!! 解决方案 先读出文件的内容,然后通过 strstr 等类似的功能函数完成字符串是否存在的判断 解决方案二: 参考一下这个 C语言程序,在文件中查找指定字符串出现的次数http://wenda.haosou.com/q/1382138287067435

字符串匹配的KMP算法

字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD"? 许多算法可以完成这个任务,Knuth-Morris-Pratt算法(简称KMP)是最常用的之一.它以三个发明者命名,起头的那个K就是著名科学家Donald Knuth. 这种算法不太容易理解,网上有很多解释,但读起来都很费劲.直到读到Jake Boxer的文章,我才真正理解这种算法.下面,我用自己的语言

[算法系列之十二]字符串匹配之蛮力匹配

引言 字符串匹配是数据库开发和文字处理软件的关键.幸运的是所有现代编程语言和字符串库函数,帮助我们的日常工作.不过理解他们的原理还是比较重要的. 字符串算法主要可以分为几类.字符串匹配就是其中之一.当我们提到字符串匹配算法,最基本的方法就是所谓的蛮力解法,这意味着我们需要检查每一个文本串中的字符是否和匹配串相匹配.一般来说我们有文本串和一个匹配串(通常匹配串短于文本串).我们需要做的就是回答这个匹配串是否出现在文本串中. 概述 字符串蛮力匹配法的原理非常简单.我们必须检查匹配串的第一个字符与文本

java-android正则表达式 字符串匹配

问题描述 android正则表达式 字符串匹配 现在在做一个功能,匹配编辑框内字符串 符合"数字+英文字母大小写+符号" 我先写了个下面的表达式在纯JAVA程序里跑没问题,放到android程序里就出问题了,比如"+",加号就不行了 Pattern pattern = Pattern.compile("[A-Za-z0-9p{Punct}]*"); 请问如何写一个符合"数字+英文大小写+符号"的正则表达式? 解决方案 d+[a

位置-字符串匹配——问题来源DNA序列的k-mer index问题

问题描述 字符串匹配--问题来源DNA序列的k-mer index问题 给定一个DNA序列,这个系列只含有4个字母ATCG,如 S ="CTGTACTGTAT".给定一个整数值k,从S的第一个位置开始,取一连续k个字母的短串,称之为k-mer(如k= 5,则此短串为CTGTA), 然后从S的第二个位置, 取另一k-mer(如k= 5,则此短串为TGTAC),这样直至S的末端,就得一个集合,包含全部k-mer . 如对序列S来说,所有5-mer为{CTGTA,TGTAC,GTACT,TA

模糊字符串匹配:双重解密算法

名称匹配的一个大问题是错误的倾向.有许多不同的方式,人们拼写相同的名字,打字错误,误读了另一个人说的话.有许多方法可以免费形式的语言数据被破坏.当您需要搜索/匹配不良数据时,会导致许多头疼. 有很多不同的方法来解决它.像Levenshtein算法一样,它计算出使一个字符串匹配另一个字符串需要进行多少次编辑.或者检查字符串组成的较小序列的NGram算法,并将它们与一个同义词串的序列进行比较.然后有语音算法根据"声音"如何编码字符串.就像SoundEx或Double Metaphone算法

[算法系列之二十六]字符串匹配之KMP算法

一 简介 KMP算法是一种改进的字符串匹配算法,由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现,因此人们称它为克努特-莫里斯-普拉特操作(简称KMP算法).KMP算法的关键是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的. 二 基于部分匹配表的KMP算法 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含搜索串"ABCDABD"? 步骤1:字符串"BBC ABC