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.       
目录
相关文章
Uva10001 Garden of Eden
Uva10001 Garden of Eden
60 0
uva10112 Myacm Triangles
uva10112 Myacm Triangles
51 0
uva375 Inscribed Circles and Isosceles Triangles
uva375 Inscribed Circles and Isosceles Triangles
55 0
概率dp - UVA 11021 Tribles
Tribles  Problem's Link:  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059   Mean:  有k个细菌,每个细菌只能存活一天,在死去之前可能会分裂出0,1,2....n-1个细菌,对应的概率为p0,p1,p2....pn-1。
839 0
|
机器学习/深度学习
uva 12470 Tribonacci
点击打开uva12470  思路: 矩阵快速幂 分析: 1 裸题 代码: /************************************************ * By: chenguolin ...
998 0
|
人工智能
uva 305 Joseph
点击打开链接uva 305 思路: 数学+打表 分析: 1 传统的约瑟夫问题是给定n个人和m,每次数m次把当前这个人踢出局,问最后留下的一个人的编号 2 这一题是前k个人是好人,后面k个是坏人。
1055 0
uva 1388 - Graveyard
点击打开链接uva1388 思路:数学 分析: 1 我们把原先的n个墓碑看成是园内的正n变形,现在的n+m个墓碑看成是园内的正n+m变形。那么通过画图我们可以知道当这个两个正多边形有一个点重合的时候移动的总距离最小 2 那么我们把这个圆进...
1023 0
|
BI
uva11729
题意:有n个人需要你分配任务,交代任务需要bi时间,执行任务需要ji时间,要求最早完成任务,请输出最后完成对的工作的时间。类型:贪心(先排序再处理)代码: #include #include #include #include using namespace std; int m...
719 0