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月前
uva 10340 all in all
输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。
19 0
|
8月前
UVa11776 - Oh Your Royal Greediness!
UVa11776 - Oh Your Royal Greediness!
36 0
|
8月前
uva10112 Myacm Triangles
uva10112 Myacm Triangles
25 0
|
机器学习/深度学习
uva 11538 Chess Queen
点击打开链接 题意:给定一个n*m的矩阵,问有多少种方法放置两个相互攻击的皇后?规定在同一行同一列和同对角线的能够相互攻击 思路: 1 先考虑同一行的情况,n行就有n种情况,每一行有m*(m-1)种,总的是n*m*(m-1); 2 考虑同...
794 0
|
机器学习/深度学习 人工智能
uva 10870 Recurrences
点击打开uva 10870 思路:构造矩阵+矩阵快速幂 分析: 1 题目给定f(n)的表达式 f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n -3) + .
716 0
uva 10273 Eat or Not to Eat?
点击打开链接uva 10273 思路: 暴力求解 分析: 1 题目要求没有吃掉的奶牛的个数已经最后一次吃掉奶牛的天数 2 没有其它的方法只能暴力,对于n头牛的n个周期求最小公倍数,然后在2个公倍数之内暴力求解 代码: #inclu...
788 0
uva 1203 Argus
点击打开链接uva 1203 思路: 优先队列 分析: 1 题目要求前k个事件的编号,我们利用优先队列来维护即可 2 优先队列保存的是一个struct,因此我们需要重载 s.
1278 0

热门文章

最新文章