-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVA409.cpp
54 lines (54 loc) · 1.1 KB
/
UVA409.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
char *strlwr(char *str)
{
unsigned char *p = (unsigned char *)str;
while (*p) {
*p = tolower((unsigned char)*p);
p++;
}
return str;
}
int main()
{
int k, e, c = 1;
while (scanf("%d %d", &k, &e) != EOF) {
getchar();
char keyword[30][100] = { 0 }, text[30][100] = { 0 }, *ptr, buffer[100];
int count[30] = { 0 }, m = 0;
for (int i = 0; i<30; i++)
count[i] = 0;
for (int i = 0; i < k; i++)
gets_s(keyword[i]);
for (int i = 0; i < e; i++) {
gets_s(buffer);
for (int p = 0; p < strlen(buffer); p++)
text[i][p] = buffer[p];
strlwr(buffer);
ptr = strtok(buffer, " ");
while (ptr != NULL) {
for (int z = 0; z<strlen(ptr); z++)
if (isalnum(ptr[z]) == 0)
ptr[z] = '\0';
for (int j = 0; j < k; j++) {
if (strcmp(ptr, keyword[j]) == 0) {
count[i]++;
break;
}
}
ptr = strtok(NULL, " ");
}
if (count[i] > m)
m = count[i];
}
printf("Excuse Set #%d\n", c);
c++;
for (int i = 0; i < e; i++) {
if (m == count[i])
puts(text[i]);
}
printf("\n");
}
}