Excuses, Excuses! UVA 409

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int get_word(int);
void convert_word();
int str_cmp();

char key[100][100];//保存关键词
char word[100];//保存从excuse中提取出来的词
char exc[100][100];//保存excuses
int  cnt[100];//记录每个excuse中keyword出现的次数
int max=0,j,K,E;

int main(){
 int i,N=1;
 //freopen("data","r",stdin);
 while(~scanf("%d%d",&K,&E)){
  for(i=0;i<K;i++)
   scanf("%s\n",key[i]);
  for(i=0;i<E;i++)
   gets(exc[i]);

  for(i=0;i<E;i++)
   cnt[i]=0;

  max=0;

  for(i=0;i<E;i++){
   j=0;//j为在读取excuse中单词时的标记,每新读一个excuse都要更新
   while(get_word(i)){//从excuse中提取单词
    convert_word();//将单词转化为小写字母
    if(str_cmp())//单词是否为keyword
     cnt[i]++;
    max=max>cnt[i]?max:cnt[i];
   }
  }  

  printf("Excuse Set #%d\n",N++);
  for(i=0;i<E;i++)
   if(cnt[i]==max)
    printf("%s\n",exc[i]);

   putchar('\n');

 }

return 0;
}

int get_word(int i){
 char c;
 int k=0;

 while(exc[i][j]!='\0'){
  while(!isalpha(exc[i][j])&&exc[i][j]!='\0')
  j++;

  if(exc[i][j]=='\0')
  return 0;

  word[k++]=exc[i][j++];
  while(isalpha(exc[i][j]))
  word[k++]=exc[i][j++];

  word[k]='\0';
  return 1;
 }

 return 0;
}

void convert_word(){
 int len=strlen(word),i;

 for(i=0;i<len;i++)
  if(isupper(word[i]))
   word[i]=tolower(word[i]);
 return ;
}

int str_cmp(){
 int i;

 for(i=0;i<K;i++)
  if(strcmp(key[i],word)==0)
   return 1;

 return 0;
}

Excuses, Excuses! UVA 409

时间: 2024-10-12 12:37:55

Excuses, Excuses! UVA 409的相关文章

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

UVA (POJ 1598)Excuses, Excuses!

Excuses, Excuses! Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Excuses, Excuses!  Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid ser

【HDOJ】1606 Excuses, Excuses!

简单字符串. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXLEN 105 5 #define MAXN 25 6 7 char keys[MAXN][MAXN]; 8 char lines[MAXN][MAXLEN]; 9 int nums[MAXN]; 10 11 int main() { 12 int case_n = 0; 13 int n, m, max; 14 int i, j, k, v; 15 cha

Excuses, Excuses! (map , string )

Excuses, Excuses! Problem 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 as

POJ1598 ZOJ1315 HDU1606 UVA409 UVALive5493 Excuses, Excuses!【文本】

Excuses, Excuses! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4701 Accepted: 1602 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 t

UVA 409 Excuses, Excuses!

题目大意:给定几个keywords,再给几个excuses,要求从中找出keywords最多的excuse.如果有几个excuse一样多,就都输出来.其中要求出现的keyword是有条件的: 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 ex

UVA 409 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

Problem B: Excuses, Excuses!

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 progr

小白书训练-Excuses, Excuses!m

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=350 题意:没读懂题让人WA到死啊啊啊!大体的意思很简单,就是给你n个单词,m个句子,问包含最多单词的句子是什么,要注意的是,找的是单词,不是字符串,说白了,就是被空格和标点符号明确分开的字符片段,不能直接上find><!!!需要对整个句子划分,然后对比查找. 代码: #