`
SunnyYoona
  • 浏览: 367081 次
社区版块
存档分类
最新评论

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 throughK+1 each contain exactly one keyword.
  • LinesK+2 throughK+1+Eeach contain exactly one excuse.
  • All keywords in the keyword list will contain only contiguous lower case alphabetic characters of lengthL(tex2html_wrap_inline42) and will occupy columns 1 throughLin 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!

【代码】:

  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. charkeywords[21][21];
  13. charstr[21][101];
  14. //匹配
  15. intMatch(chartemp[],intM){
  16. for(inti=0;i<M;i++){
  17. if(strcmp(temp,keywords[i])==0){
  18. //printf("%s",temp);
  19. return1;
  20. }
  21. }
  22. return0;
  23. }
  24. intmain(){
  25. inti,j,M,N,k,Max,MaxIndex,Case=1;
  26. chartemp[21];
  27. intcount[21];
  28. //freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin);
  29. while(scanf("%d%d\n",&M,&N)!=EOF){
  30. memset(count,0,sizeof(int)*N);
  31. Max=-1;
  32. //输入关键词
  33. for(i=0;i<M;i++){
  34. gets(keywords[i]);
  35. }
  36. //输入借口
  37. for(i=0;i<N;i++){
  38. gets(str[i]);
  39. intlen=strlen(str[i]);
  40. for(j=0;j<len;){
  41. k=0;
  42. //提取单词
  43. while((str[i][j]>='a'&&str[i][j]<='z')||(str[i][j]>='A'&&str[i][j]<='Z')){
  44. //转换为小写
  45. if(str[i][j]>='A'&&str[i][j]<='Z'){
  46. temp[k++]=str[i][j]-'A'+'a';
  47. }
  48. else{
  49. temp[k++]=str[i][j];
  50. }
  51. j++;
  52. }
  53. j++;
  54. temp[k]='\0';
  55. //和关键词进行匹配
  56. if(Match(temp,M)){
  57. count[i]++;
  58. }
  59. }
  60. //最大借口关键词个数
  61. if(Max<count[i]){
  62. Max=count[i];
  63. }
  64. }//for
  65. //输出
  66. printf("ExcuseSet#%d\n",Case);
  67. Case++;
  68. //最差借口
  69. for(i=0;i<N;i++){
  70. if(Max==count[i]){
  71. puts(str[i]);
  72. }
  73. }
  74. printf("\n");
  75. }
  76. return0;
  77. }
分享到:
评论

相关推荐

    Android代码-Programmer Excuses

    Programmer Execuses Simple client which uses pe-api. It's now available on Play Store It's using SwipeRefreshLayout for swipe-down-to-refresh layout. ButterKinife for view injections. ...

    Developer Excuses-crx插件

    语言:English 获取每个新选项卡的全新开发者借口! 来自www.developerexcuses.com的借口。 获取每个新选项卡的全新开发者借口! 来自... 万岁!...全新主题::sun:太阳,:unicorn:梦想和:herb:草!

    Dev Excuses-crx插件

    语言:English (UK) 在最需要的时候快速找个借口 当开发人员的代码无法运行时,它为开发人员提供了一个快速借口的工具

    Teachers' perceptions of students' excuses for academic difficulties

    Teachers' perceptions of students' excuses for academic difficulties 146 Ferguson MEISELS, S. J. (1989). High-stakes testing in kindergarten. Educational Leadership, 46(7), 16-22. MOSBURO, J. W. ...

    Excuses-Generator

    香草JS的Hello World 通过在gitpod中打开此模板,在30秒内开始编码: 手动安装 切记先安装npm软件包: $ npm install 建立并开始编码! 第一次构建应用程序... $ npm run start ...1)如何运行我的代码?...

    Iron-Clad Java_Building Secure Web Applications-McGraw Hill(2015).epub

    All too often, businesses roll the dice and short product security, explaining away incidents when they occur with excuses like: “hackers are becoming more sophisticated,” “security is too ...

    Service Support-英文原版

    Preface.........................................................................................................................................- 1 - 1 Introduction.......................................

    ZJU_ACM_All_Anwer 搞编程的都知道的浙江大学A 题库.本书 集了所有经 Z 题解集,集合并附 Mathimaticsumerical algorithms 数值算法

    1315 Excuses, Excuses! 简单题 1151 Word Reversal 简单题,好像是什么Practice的…… 1170 String Matching 简单题 1174 Skip Letter Code 不错的简单题 1175 Word Process Machine 简单题 1181 Word ...

    浙江大学ACM题解/ZJU 题型分类

    1315 Excuses, Excuses! 简单题 1151 Word Reversal 简单题,好像是什么Practice的…… 1170 String Matching 简单题 1174 Skip Letter Code 不错的简单题 1175 Word Process Machine 简单题 1181 Word ...

    xkcd-excuse-generator:使用XKCD漫画作为_all_借口的基础的无服务器图像生成器!

    XKCD借口生成器以漂亮的漫画风格产生自己的借口! 转到并从此转到: 对此: 用一个简单的表格! 原始创建是作为2017年9月12日举行的和2017年9月29日举行的的示例,在此我就无服务器技术进行。 提供的错误监控 :red_...

    Perl Best Practices

    "There are no more excuses for writing bad Perl programs. All levels of Perl programmer will be more productive after reading this book." -- Peter Scott "Perl Best Practices will be the next big ...

    计算机网络_自顶向下方法_第四版_课后习题答案

    Diplomatic protocols also allow for either Alice or Bob to politely cancel the engagement if they have reasonable excuses. 3. A networking program usually has two programs, each running on a ...

    AndroidCommunicator:IoC容器,用于从Android调用Web服务-开源

    还提供了一个名为PhotoSpeller的演示应用程序,该应用程序用照片拼写了从用户或通过调用以下服务之一获得的文本:QuoteOfThe Day或Excuses。 这些照片是通过调用Flickr或Google图片服务获得的。

    The.Startup.Equation.A.Visual.Guidebook.to.Building.Your.Startup

    No Money, No Excuses Chapter 13. Startup Marketing Alchemy Chapter 14. ROI of Happy Customers Chapter 15. Scaling to New Heights Chapter 16. Always Be Innovating Chapter 17. The Exponential Power of ...

    教师对学生学业困难借口的看法

    Teachers' perceptions of students' excuses for academic difficulties 146 Ferguson MEISELS, S. J. (1989). High-stakes testing in kindergarten. Educational Leadership, 46(7), 16-22. MOSBURO, J. W. ...

    Chrome Install

    We all know that exercise is important – vital, in fact. Yet, one of the most common excuses for not exercising enough is “I can’t find time for exercise.”

    OVERSQUAD-crx插件

    Oversquad流通知器 Rest通知quis passe chez les流光OVERSQUAD! Désqu'un stream estlancé...维护人员,vous n'aurez和d'excuses;)NB:Cette扩展estdéveloppéepar JuJoue。 http://jujoue.me/ 支持语言:Français

Global site tag (gtag.js) - Google Analytics