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 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.

所以其实就是在句子里面找单词。这个单词可以夹在非字母字符的中间,如:123what234。所以可以在句子里面搜索一个个的单词再去进行匹配。

#include<stdio.h>
#include<string.h>
#include<ctype.h>
char keywords[105][105];
char excuses[106][105],change[106][105];
int K,E;
int search(int t)
{
	int l=strlen(change[t]);
	char s[105];
	int j=0,k,num=0;
	for(int i=0;i<l;i++)
	{
		if(isalpha(change[t][i]))s[j++]=change[t][i];   //找到一个连续的单词,因为不连续的是不符合的。
		else {
			s[j]='\0';
			j=0;
			for(k=0;k<K;k++)
			if(strcmp(s,keywords[k])==0)num++;
		}
	}
	return num;

}
int main()
{
	int i,j,k,l,t[105],maxi,cases=0;

	while(scanf("%d%d",&K,&E)!=EOF)
	{
		maxi=0;cases++;
		memset(t,0,sizeof(t));
		for(i=0;i<K;i++)
		{
			scanf("%s",keywords[i]);
		}
			getchar();
		for(i=0;i<E;i++)
		{
			t[i]=0;

			gets(excuses[i]);

			for(k=0;k<strlen(excuses[i]);k++)
			{if(excuses[i][k]>='A'&&excuses[i][k]<='Z')
			change[i][k]=excuses[i][k]+32;
			else change[i][k]=excuses[i][k];}
			 t[i]=search(i);
			if(t[i]>maxi)maxi=t[i];
		}
		printf("Excuse Set #%d\n",cases);
		for(i=0;i<E;i++){
		//	printf("%s\n",change[i]);
		//	printf("%d\n",t[i]);
			if(maxi==t[i])printf("%s\n",excuses[i]);
		}
		printf("\n");
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-24 17:17:13

UVA 409 Excuses, Excuses!的相关文章

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

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中keywor

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! (字符处理)

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><!!!需要对整个句子划分,然后对比查找. 代码: #