您的位置:首页 > 其它

UVa 409 - Excuses, Excuses!

2013-04-10 21:41 561 查看
#include <cstdio>
#include <cstring>
#include <cctype>
#include <map>
using namespace std;

char keywords[22][22]; //keywords
char excuses_o[22][72]; //原始excuses
char excuses[22][72]; //转化为小写后
int e_k[22]; //每个语句含有keyword数统计

void lower(int e)
{
int i;
char *p;
for(i=0; i<e; i++) {
p = excuses[i];
while(*p) {
*p = tolower(*p);
p++;
}
}
}

bool in_keywords(int k, char *word) {
int i;
for(i=0; i<k; i++) {
if(strcmp(word, keywords[i]) == 0) return true;
}
return false;
}

int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif

int k, e, i, l, max, j=0;
char *p;
bool found;
char word[72];
while(scanf("%d%d\n", &k, &e)==2) {
j++;
for(i=0; i<k; i++) {
scanf("%s\n", keywords[i]);
}
for(i=0; i<e; i++) {
fgets(excuses_o[i], sizeof(excuses_o[0]), stdin);
}
memcpy(excuses, excuses_o, sizeof(excuses_o));
memset(e_k, 0, sizeof(e_k));
lower(e);
max = 0;
for(i=0; i<e; i++) {
l = 0;
found = false;
p = excuses[i];
while(*p || found) {
if(isalpha(*p)) {
found = true;
word[l++] = *p;
} else if(found){
word[l] = 0;
found = false;
if(in_keywords(k, word)) {
e_k[i]++;
if(e_k[i] > max) max = e_k[i];
}
l = 0;
}
p++;
}
}

printf("Excuse Set #%d\n", j);
for(i=0; i<e; i++) {
if(e_k[i] == max) {
printf("%s", excuses_o[i]);
}
}
printf("\n");
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: