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> # ...
随机推荐
- ComboBox 自动调整组合框下拉部分的宽度
/// <summary> /// ComboBox 自动调整组合框下拉部分的宽度 /// </summary> void Resiz ...
- mouseover与mouseenter与mousemove差额mouseout与mouseleave差额
<1> HTML <html> <head> <title></title> </head> <body> < ...
- MEF初体验之十二:Composition Batch
一个MEF容器实例是不可变的.如果catalog支持改变(像观察一个目录的改变)或是如果你的代码在运行时添加或移除部件,改变都可能发生.以前,你不得不作出改变并在组合容器上调用它的组合方法.在Prev ...
- ehCache浅谈(转)
ehcache FAQ中提到 Remember that a value in a cache element is globally accessible from multiple threads ...
- bonecp使用数据源
bonecp.properties jdbc.driverClass=oracle.jdbc.driver.OracleDriver jdbc.jdbcUrl=jdbc:oracle:thin:@19 ...
- 算法----选择排序(select sort)
排序不是一个时间的数组进行排序,找到最小的元素,其与阵列的第一个元素交换,因此,排序的数组. 算法: void sort::select_sort(int* a,const int n) { for( ...
- HDU 3313 Key Vertex(dfs + bfs)
HDU 3313 Key Vertex 题目链接 题意:一个有向无环图.求s,t之间的割点 思路:先spfa找一条最短路出来,假设不存在.就n个都是割点. 然后每次从s进行dfs,找到能经过最短路上的 ...
- HDU 1711 Number Sequence(kmp)
Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...
- 推荐几个我一直在使用chrome小工具(上)
我用的chrome插件挺多的,所谓工欲善其事必先利其器,我热衷于搜寻好用的工具来让我平时的工作事半功倍. 以下介绍几款我正在用的感觉还不错的插件,假设大家还有其他好用的(肯定有,chrome插件库太庞 ...
- BI—脚不一样的感觉
在这个网络智能的时代,假设生活和智能挂不上边那就太落后啦!尤其IT行业更是如此,前不久还在用微软的office做报表,这几天就吵吵着换成BI,那么BI是什么?有什么用?怎么用?等等带着这一系列的问题来 ...