Uva 409-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 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 #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!
还是串处理。。
题意:给一个字典,然后给e行串 问哪行串里面的出现的单词次数最多,有多个则输出多个
思路:字典扔set里。。然后gets成行读进来转换成单词哎个查询。。然后就完了。。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define maxn 360
#define pp pair<int,int>
#define INF 0x3f3f3f3f
#define max(x,y) ( ((x) > (y)) ? (x) : (y) )
#define min(x,y) ( ((x) > (y)) ? (y) : (x) )
using namespace std;
char tem[88],exc[22][77];
int k,e,p,ans[22];
int main()
{
int cas=1;
while(~scanf("%d%d",&k,&e))
{
getchar();
memset(ans,0,sizeof(ans));
string x;set <string> s;
while(k--)
{
cin>>x;
s.insert(x);
}
getchar();
for(int i=0;i<e;i++)
{
gets(exc[i]);
int len=strlen(exc[i]);
for(int j=0;j<=len;)
if(isalpha(exc[i][j]))
{
p=0;tem[p++]=tolower(exc[i][j]);j++;
while(isalpha(exc[i][j]))
tem[p++]=tolower(exc[i][j++]);
tem[p++]='\0';string y(tem);
if(s.count(y))
ans[i]++;
}
else
j++;
}
printf("Excuse Set #%d\n",cas++);
int Max=-INF;
for(int i=0;i<e;i++)
Max=max(Max,ans[i]);
for(int i=0;i<e;i++)
if(ans[i]==Max)
printf("%s\n",exc[i]);
puts("");
}
return 0;
}
Uva 409-Excuses, Excuses!(串)的更多相关文章
- UVa 409 Excuses, Excuses!
哈哈,虽然是一道字符串水题,可是拿到一个1A还是很开心的! 题意就是给一些keywords(子串)和Excuse(母串),然后输出包含keywords最多的Excuse,如果相等的话,按任意顺序全部输 ...
- Problem B: Excuses, Excuses!
Description Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame ex ...
- UVa 129 困难的串
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 129困难的串【DFS】
题目链接 题目大意: 给出n,l:要求按特定格式输出由前l个大写字母构成的按字母表排列的第n个没有连续重复子串的字符串以及该字符串长度. 此题是一道dfs递归回溯的基础题,难点在于对当前字符串是否有连 ...
- 【HDOJ】1606 Excuses, Excuses!
简单字符串. #include <cstdio> #include <cstring> #define MAXLEN 105 #define MAXN 25 char keys ...
- UVa409_Excuses, Excuses!(小白书字符串专题)
解题报告 题意: 找包括单词最多的串.有多个按顺序输出 思路: 字典树爆. #include <cstdio> #include <cstring> #include < ...
- UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494
白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Volume 1. String(uva)
10361 - Automatic Poetry #include <iostream> #include <string> #include <cstdio> # ...
随机推荐
- ruby简单的基本 3
类 Ruby一切都是对象,它包含了一个恒定.例如,可以使用.class物业查看对象的类型,你可以看一下1.class.你会发现常1类型是Fixnum,1但它是Fixnum的一个例子. Ruby本类cl ...
- ASP.NET分页正品—分页真
承接上篇博文<ASP.NET真假分页-假分页>:http://blog.csdn.net/u010773667/article/details/38845009,继续解说ASP.NE ...
- HDU更多的学校比赛9场 HDU 4965Fast Matrix Calculation【矩阵运算+数学技巧】
困难,.,真,,,不是太困难 的问题是,有一个矩阵运算优化 您有权发言权N*K矩阵A给K*N矩阵B(1<=N<=1000 && 1=<K<=6).他们拿起了第一 ...
- 单链表---java实现
单链表优点:1.不需要预先给出元素个数. 2.单链表插入删除时不需要移动数据元素. 单链表缺点:1.每个节点有指针,空间利用率低. 2.单链表不支持随机读取数据. Node.java package ...
- Http与协议TCP协议简单易懂
于C#编写代码,很多时候会遇到Http协议或TCP合约,这里做一个简单的了解. TCP对应于该传送层协议,和HTTP对应于应用层协议,从本质上讲,两者是没有可比性.Http该协议是基于TCP之上的,当 ...
- CF 444B(DZY Loves FFT-时间复杂度)
B. DZY Loves FFT time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- StackExchange.Redis 使用-配置 (四)
Configurationredis有很多不同的方法来配置连接字符串 , StackExchange.Redis 提供了一个丰富的配置模型,当调用Connect 或者 ConnectAsync 时需要 ...
- <ASP.NET4 从入门到精通>学习笔记1
非常久没有写东西了,今日有时间,開始整理一下关于ASP.NET 4的学习笔记.提醒自己,也欢迎评论. 概述一共分为6个大的部分,兴许文章.将依据每一个部分进行整理,本读书笔记仅仅是整理关键点,对于啰嗦 ...
- UVa 10491 - Cows and Cars
題目:有m+n個們,每個門後面有牛或者車:有n仅仅牛,m輛車,你選擇当中1個: 然後打開当中的k你沒有選中的門後是牛的,問你改變選時得到車的概率. 說明:數學題,概率.全概率公式就可以: 說明:第10 ...
- NSUserDefaults API简单的介绍和使用英文文件
Overview The NSUserDefaults class provides a programmatic interface for interacting with the default ...