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> # ...
随机推荐
- org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for...
异常详情: Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at ta ...
- 认识javascript范围和作用域链
范围 作用域就是变量和函数的可訪问范围.控制着变量和函数的可见性与生命周期,在JavaScript中变量的作用域有全局作用域和局部作用域. 全局和局部作用域以下用一张图来解释: 单纯的JavaScri ...
- IOC/DI的基本思想
IOC/DI的基本思想 1.把程序之间的依赖关系去掉 2.把程序对象设置到IOC/DI容器的配置中作为Bean 3.由IOC/D.容器来管理Bean的创建和实例化 4.由IOC/DI容器来把Bean之 ...
- [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify uniq
angularjs 使用ng-repeat报错 <div ng-init="words = ['高校','高校','高校']" ng-repeat="word in ...
- SQL 2008 SP2 找不到SQL Server Engine
原文:SQL 2008 SP2 找不到SQL Server Engine 最近我有个客户碰到一个很奇怪的问题.他安装SQL server 2008 SP2的时候, SP2的安装程序无法找到SQL se ...
- curl 要么 file_get_contents 获得授权页面的方法的必要性
今天,需要工作,需要使用 curl / file_get_contents 获得授权的必要性(Authorization)的页面内容.解决后写了这篇文章分享给大家. php curl 扩展,可以在se ...
- c#左右socket连接超时控制方案
之前有一个项目中使用Remoting技术.当远程地址无效或server不执行,访问远程对象的方法,它会经过几十秒的时间来抛出异常秒. 由于我使用tcp状态.因此,认为可以使用socket为了测试连接, ...
- hdu3480二维斜率优化DP
Division Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 999999/400000 K (Java/Others) Tota ...
- Git Config(转)
一.Git已经在你的系统中了,你会做一些事情来客户化你的Git环境. 你只需要做这些设置一次:即使你升级了,他们也会绑定到你的环境中.你也可以在任何时刻通过运行命令来重新更改这些设置. ...
- 微软发布Win10开发者指南视频
假设你是一个开发者,推荐你看看微软今天推出了一系列视频,标题是Win10开发人员指南,总体长度6时,多达22章内容,介绍很广泛.其实,即使你是编程新手或仅有兴趣,也值得一看. 开发人员Jerry Ni ...