POJ1598 ZOJ1315 Excuses,Excuses!

//4_7_20:	Excuses,Excuses! 寻找在借口中的最多关键字 POJ1598 ZOJ1315
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char enter,key[25][25],sen[25][100],temp[100],word[100];
int  key_cnt[25],sen_cnt[25];
int main()
{
	int i,j,k,K,E,max,cnt,flag,count = 1,length;
	while(scanf("%d%d%c",&K,&E,&enter) != EOF)
	{
		memset(sen_cnt,0,sizeof(sen_cnt));
		for(i = 0;i < K;i ++)	cin.getline(key[i],20);
		for(i = 0;i < E;i ++)				//输入借口串
		{
			cin.getline(sen[i],100);
			strcpy(temp,sen[i]);
			j = 0;
			while(sen[i][j])
			{
				if(sen[i][j] >= 'A' && sen[i][j] <= 'Z')	sen[i][j] += 32;
				j ++;
			}
			memset(key_cnt,0,sizeof(key_cnt));	//对于每个借口串中的关键字多少不同
			j = cnt = flag = 0;							//表示还不是单词
			length = strlen(sen[i]);
			while(j <= length)
			{
				if(sen[i][j] >= 'a' && sen[i][j] <= 'z')
				{
					if(flag == 0)
					{
						word[cnt++] = sen[i][j++];
						flag = 1;
					}
					else	word[cnt++] = sen[i][j++];
				}
				else
				{
					if(flag == 0)	j++;
					else
					{
						word[cnt] = '\0';
						for(k = 0;k < K;k ++)
							if(strcmp(word,key[k]) == 0)
							{
								key_cnt[k]++;
								break;
							}
						cnt = flag = 0;
						j ++;
					}
				}
			}
			for(j = 0;j < K;j ++)	sen_cnt[i] += key_cnt[j];
			strcpy(sen[i],temp);
		}
		printf("Excuse Set #%d\n",count++);
		max = sen_cnt[0];
		for(i = 1;i < E;i ++)	if(sen_cnt[i] > max)	max = sen_cnt[i];
		for(i = 0;i < E;i ++)	if(sen_cnt[i] == max)	printf("%s\n",sen[i]);
		printf("\n");
	}
	return 0;
}
/*测试结果:通过POJ1598 ZOJ1315检测
6 3
dog
ate
homework
canary
died
home
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.
Excuse Set #1
Can you believe my dog died after eating my canary... AND MY HOMEWORK?

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.
Excuse Set #2
Can you believe my dog died after eating my canary... AND MY HOMEWORK?

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?
Excuse Set #3
I am having a superhighway built in my bedroom.
There was a thermonuclear war!

^Z
请按任意键继续. . .
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值