UVA之409 - Excuses, Excuses!

简介:

 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 ( 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!

【代码】:

[cpp]  view plain copy
  1. /********************************* 
  2. *   日期:2013-4-29 
  3. *   作者:SJF0115 
  4. *   题号: 题目409 - Excuses, Excuses! 
  5. *   来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=350 
  6. *   结果:AC 
  7. *   来源:UVA 
  8. *   总结: 
  9. **********************************/  
  10. #include<stdio.h>  
  11. #include<string.h>  
  12. char keywords[21][21];  
  13. char str[21][101];  
  14. //匹配  
  15. int Match(char temp[],int M){  
  16.     for(int i = 0;i < M;i++){  
  17.         if(strcmp(temp,keywords[i]) == 0){  
  18.             //printf("%s",temp);  
  19.             return 1;  
  20.         }  
  21.     }  
  22.     return 0;  
  23. }  
  24.   
  25. int main (){  
  26.     int i,j,M,N,k,Max,MaxIndex,Case = 1;  
  27.     char temp[21];  
  28.     int count[21];  
  29.     //freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin);    
  30.     while(scanf("%d %d\n",&M,&N) != EOF){  
  31.         memset(count,0,sizeof(int)*N);  
  32.         Max = -1;  
  33.         //输入关键词  
  34.         for(i = 0;i < M;i++){  
  35.             gets(keywords[i]);  
  36.         }  
  37.         //输入借口  
  38.         for(i = 0;i < N;i++){  
  39.             gets(str[i]);  
  40.             int len = strlen(str[i]);  
  41.             for(j = 0;j < len;){  
  42.                 k = 0;  
  43.                 //提取单词  
  44.                 while((str[i][j] >= 'a' && str[i][j] <= 'z') || (str[i][j] >= 'A' && str[i][j] <= 'Z')){  
  45.                     //转换为小写  
  46.                     if(str[i][j] >= 'A' && str[i][j] <= 'Z'){  
  47.                         temp[k++] = str[i][j] - 'A' + 'a';  
  48.                     }  
  49.                     else{  
  50.                         temp[k++] = str[i][j];  
  51.                     }  
  52.                     j++;  
  53.                 }  
  54.                 j++;  
  55.                 temp[k] = '\0';  
  56.                 //和关键词进行匹配  
  57.                 if(Match(temp,M)){  
  58.                     count[i] ++;  
  59.                 }  
  60.             }  
  61.             //最大借口关键词个数  
  62.             if(Max < count[i]){  
  63.                 Max = count[i];  
  64.             }  
  65.         }//for  
  66.         //输出  
  67.         printf("Excuse Set #%d\n",Case);  
  68.         Case++;  
  69.         //最差借口  
  70.         for(i = 0;i < N;i++){  
  71.             if(Max == count[i]){  
  72.                 puts(str[i]);  
  73.             }  
  74.         }  
  75.         printf("\n");  
  76.     }  
  77.     return 0;  
  78. }  
  79.   
  80.       
目录
相关文章
|
6月前
|
存储 NoSQL 关系型数据库
Apifox与Apipost数据库连接功能详细对比,让接口管理更高效!
Apipost 更加全面:无论是关系型还是非关系型数据库,它都为开发者提供了一站式解决方案,非常适合数据库架构复杂的大型项目。相对来说,Apifox偏重关系型分析和管理:若项目主要需求在于管理关系型数据库,而对非关系型的依赖较小,Apifox倒是可以应付。
161 2
|
缓存 应用服务中间件 Apache
缓存代理服务器的实现机制和技术选型
缓存代理服务器是一种特殊的代理服务器,其主要功能是缓存从目标服务器(通常是Web服务器)获取的数据,并在客户端再次请求相同数据时直接提供缓存的数据。通过缓存代理服务器可以加快访问速度并减轻目标服务器的负载。
505 104
|
JavaScript
vue + element-ui + vue-clipboard2 实现文字复制粘贴功能与提示
1、在所在项目下安装插件 ```js npm install vue-clipboard2 --save ``` 2、在所在项目的index.js注入vue-clipboard2 ```js import VueClipboard from 'vue-clipboard2' Vue.use(VueClipboard) ``` 3、使用 ```html <div> <el-button size="mini" type="primary" icon="el-icon-copy-document" round class="copy-btn" v-clipboard:copy="要
304 2
【操作系统】实验八 proc文件系统
【操作系统】实验八 proc文件系统
259 1
|
算法 安全 数据处理
【C++ 编程范式】理解C++ 中编程范式,选择合适的方式
【C++ 编程范式】理解C++ 中编程范式,选择合适的方式
473 2
|
算法 异构计算
m基于FPGA的RS+卷积级联编译码实现,RS用IP核实现,卷积用verilog实现,包含testbench测试文件
m基于FPGA的RS+卷积级联编译码实现,RS用IP核实现,卷积用verilog实现,包含testbench测试文件
142 0
|
区块链
量化合约交易系统开发|秒合约系统开发搭建源码
区块链还是一个透明可信的权利确认与追溯系统,一份权利一旦数字化为区块链上的通证
|
运维 监控 Kubernetes
阿里云可观测峰会-行业实践分论坛| 学习笔记(一)
快速学习阿里云可观测峰会-行业实践分论坛
阿里云可观测峰会-行业实践分论坛| 学习笔记(一)
|
Python
蜂鸣器
无人机蜂鸣器是一种用于产生声音信号的装置,通常被安装在无人机的机身上。以下是无人机蜂鸣器的一些作用:
514 0
|
网络安全 云计算 数据中心
来自马来西亚的点赞!
来自马来西亚的点赞!
87 0