Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 2299 | Accepted: 793 |
Description
Input
Output
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!
下面贴代码:
#include<iostream>
using namespace std;
char cha[50] = " 0123456789\".,!?~@#$%^&*(){}[]|+-;':"; //列出所有的分隔符
int cmp(char c, char * s) //判断字符c在不在串s中
{
int i, len;
len = strlen(s);
for(i = 0; i < len; i ++)
if(s[i] == c)
return 1;
return 0;
}
int main()
{
int m, n, i, j, num[20], max, t = 1;
char word[20][30], excuse[20][100];
while(scanf("%d %d", &m, &n) != EOF)
{
getchar();
for(i = 0; i < m; i ++) //输入keywords
scanf("%s", word[i]);
getchar();
memset(num, 0, sizeof(num)); //赋初值
max = 0;
for(i = 0; i < n; i ++) //输入excuse
{
char ch[100];
gets(excuse[i]);
int len = strlen(excuse[i]);
for(j = 0; j < len; j ++)
{
int a = 0;
while(!cmp(excuse[i][j], cha)) //判断是不是分隔符,如果不是就进
{
if(excuse[i][j] >= 'A' && excuse[i][j] <= 'Z') //把大写字母转化为小写的
ch[a ++] = excuse[i][j] + 32;
else
ch[a ++] = excuse[i][j];
j ++;
}
if(a > 0)
{
int k;
ch[a] = '\0';
for(k = 0; k < m; k ++) //逐个与keywords比较
{
if(strcmp(ch, word[k]) == 0)
break;
}
if(k < m)
num[i] ++; //关键词数加1
}
}
max = max > num[i] ? max : num[i];
}
printf("Excuse Set #%d\n", t ++); //输出
for(i = 0; i < n; i ++)
{
if(num[i] == max)
printf("%s\n", excuse[i]);
}
printf("\n");
}
return 0;
}