Problem B: Excuses, Excuses!
Description
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 ( tex2html_wrap_inline30 ) defines the number of keywords to be used in the search. The second number ( tex2html_wrap_inline32 ) 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 ( tex2html_wrap_inline42 ) 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!
#include<stdio.h>
#include<string.h>
int main()
{
int m,n,i,j,t,k,w=0;
char a[100][100],b[100][100],c[100][100],x[100];
int y;
while(scanf("%d%d",&m,&n)!=EOF)
{
int num[100]={0};
w++;
getchar();
for(i=0;i<m;i++)
{
gets(a[i]);
for(j=0;a[i][j];j++)
{
if(a[i][j]>='A'&&a[i][j]<='Z')
a[i][j]=a[i][j]+32;
}
}
for(i=0;i<n;i++)
{
gets(b[i]);
for(j=0;b[i][j];j++)
{
c[i][j]=b[i][j];
if(c[i][j]>='A'&&c[i][j]<='Z')
c[i][j]=c[i][j]+32;
}
c[i][j]='\0';
y=0;
for(j=0;c[i][j];j++)
{
if(c[i][j]>='a'&&c[i][j]<='z')
{
x[y++]=c[i][j];
}
else
{
x[y]='\0';
for(k=0;k<m;k++)
{
if(strcmp(x,a[k])==0)
{
num[i]++;
break;
}
}
y=0;
}
}
// for(i=0;i<n;i++)
// printf("%d\n",num[i]);
}
int max=0;
printf("Excuse Set #%d\n",w);
for(i=0;i<n;i++)
{
if(num[i]>=max)
max=num[i];
}
for(i=0;i<n;i++)
{
if(max==num[i])
{
printf("%s\n",b[i]);
}
}
printf("\n");
}
return 0;
}
Problem B: Excuses, Excuses!的更多相关文章
- UVa 409 Excuses, Excuses!
哈哈,虽然是一道字符串水题,可是拿到一个1A还是很开心的! 题意就是给一些keywords(子串)和Excuse(母串),然后输出包含keywords最多的Excuse,如果相等的话,按任意顺序全部输 ...
- 【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题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 1(String)
第一题:401 - Palindromes UVA : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 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 ...
随机推荐
- Openstack 的 RPC使用。
大家都已经很熟悉了RPC了. 比如说nfs就是采用的RPC通信. 尤其SUN RPC 已经成为了C语言开发的经典一种进程间调用机制. openstack 的RPC 机制, 是基于AMQP 活着其他高级 ...
- SQLite for C#
slqlite是个轻量级的数据库,是目前较为流行的小型数据库,适用于各个系统..NET自然也是支持的 1.添加2个引用System.Data.SQLite.Linq,System.Data.SQLit ...
- spm3 基本
spm3 命令 spm init //初始化一个spm模块,会生成基本配置以及测试文件等(下图). //注 初始化以后一般需要 鲜执行一下 spm install 安装默认依赖模块 index.js就 ...
- 动态加载 js
要实现动态加载JS脚本有4种方法: 1.直接document.write <script language="javascript"> document.write(& ...
- javascript操作JSON对象,增加 删除 修改
JS只能输入数字,数字和字母等的正则表达式 1.文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace( ...
- 创建XML文件
//创建XML文件 XmlDocument xmldoc = new XmlDocument(); XmlText xmltext; ...
- day7_python学习笔记_chapter9_文件
1. open(), file(), 作用完全相同 2. 语法: file_object = open(file_name, access_mode='r', buffering='-1') acce ...
- LNNVL函数使用
显示那些佣金比例(commision)不大于20%或者为NULL的员工的信息. CREATE TABLE plch_employees ( employee_id INTEGER P ...
- Unity3D Android手机开发环境配置
Unity3D Android手机开发环境配置 Date:2014-01-01 07:09 1.配置eclipse环境:首先在官网下载安装包:http://developer.android.com/ ...
- Linux ---> 监控JVM工具
Linux ---> 监控JVM工具shkingshking 发布时间: 2013/10/10 01:27 阅读: 2642 收藏: 26 点赞: 1 评论: 0 JDK内置工具使用 jps(J ...