poj1598 Excuses, Excuses!
来源:互联网 发布:波兰计算器c语言 编辑:程序博客网 时间:2024/05/17 08:09
Excuses, Excuses!
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 2357
Accepted: 811
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 (1 <= K <= 20) defines the number of keywords to be used in the search. The second number (1 <= E <= 20) 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 (1 <= L <= 20) 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 [".,!?] 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!
题意:
每次给你K个单词,再给你E行句子,问你哪些句子包含最多单词(给过你的K个单词)
其中,句子中单词是以标点符号和空格分开的,匹配不区分大小写
OK!
看到有人是用STL和sort()做的,看了一下数据量不大,而且输出时又要按顺序
所以,果断用sscanf()和暴力搜索来做,看来不用STL效率还是挺高的
MARK代码
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char str[70][100];//句子
int len[70]; //包含多少个key word
char key[25][25];//给出的key word
int k,e;
int t=0;
int i,j;
char temp_key[25];
char temp[100];
int max_len;
while(scanf("%d%d",&k,&e)!=EOF)
{
max_len=0;
for(i=0;i<k;i++)
scanf("%s",key[i]);//输入key word
getchar();
for(i=0;i<e;i++)
{
gets(str[i]); //输入句子
strcpy(temp,str[i]); //用temp来处理,不影响输出
len[i]=0;
for(j=0;temp[j]!='/0';j++)
{
if (isalpha(temp[j])) {
temp[j] = tolower(temp[j]); //转换为小写
} else {
temp[j] = ' '; //符号用空格代替,方便后面的处理
}
}
char *p=temp; //用p保存
while(sscanf(p,"%s",temp_key)>0)//每次取一个单词
{
p++; //去掉空格,防止后面的一句定位不对
p+=strlen(temp_key);
for(j=0;j<k;j++)
if(strcmp(temp_key,key[j])==0)
len[i]++;
}
if(len[i]>len[max_len])
max_len=i;
}
printf("Excuse Set #%d/n",++t);
for(i=0;i<k;i++) //之前还以为是输出一组呢,要输出全部最大的
if(len[i]==len[max_len])
printf("%s/n",str[i]);
printf("/n"); //每个例子后面要空一行
}
return 0;
}
- poj1598 Excuses, Excuses!
- poj1598 Excuses,Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- fjnu 1850 Excuses, Excuses!
- UVa 409 Excuses, Excuses!
- 409-Excuses, Excuses!
- 409 - Excuses, Excuses!
- uva 409 Excuses, Excuses!
- UVa 409 Excuses! Excuses!
- UVa 409 - Excuses, Excuses!
- uva-409 - Excuses, Excuses!
- uva409 - Excuses, Excuses!
- POJ 1598 Excuses, Excuses!
- 12.3 事件适配器XxxAdapte
- 12.4 修改组件的默认事件处理方式
- 数据挖掘 graph mining 之 ranking 介绍
- 12.5.1 Graphics类与图形绘制和组件重绘的处理
- 日记导航
- poj1598 Excuses, Excuses!
- 后台页面访问权限:页面基类&内置票据认证 使用方法
- sicily 1129
- 网上常用免费WebServices集合
- vim(3) 转帖
- C#中异步和多线程的区别
- 12.5.2 Image的内部机制
- WCF开发实战系列一:创建第一个WCF服务
- 人脑中的twitter应用与转发现象