//这题有两点需要注意的:1.有可能excuses中存在着大写字母,这就需要将其大写字母转换为小写字母再比较
//2.keysword不能是excuses中的字串,而是一个单词,具体见下面的样例!
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;
struct Info
{
int c;
string str;
};
bool mycmp(Info a, Info b)
{
return a.c > b.c;
}
int main()
{
int i, j, k, e, pos, len, tc = 0, c;
string keysword[25];
Info excuses[25], tmp[25];
while (cin >> k >> e){
tc++;
//keysword和excuses的输入
for (i = 0; i < k; i++)
cin >> keysword[i];
cin.get();
for (i = 0; i < e; i++){
getline(cin, excuses[i].str);
excuses[i].c = 0;
tmp[i].str = excuses[i].str;
tmp[i].c = excuses[i].c;
}
//讲excuses中的不是字母的转换为空格,而大写字母转换为小写,主要为后面的进行统一的比较
for (i = 0; i < e; i++){
len = excuses[i].str.length();
for (j = 0; j < len; j++){
if (isalpha(excuses[i].str[j]))
excuses[i].str[j] = tolower(excuses[i].str[j]);
else
excuses[i].str[j] = ' ';
}
}
//找出keysword中excuses中的位置,如果是一个单词的情况下就符合情况,如果只是excuses中的一个字串的情况就不符合情况!
for (i = 0; i < e; i++){
for (j = 0; j < k; j++){
pos = excuses[i].str.find(keysword[j]);
if (pos >= 0){
pos = pos + keysword[j].length();
if (excuses[i].str[pos] == ' ')
tmp[i].c++;
}
}
}
sort(tmp, tmp+e, mycmp);
cout << "Excuse Set #" << tc << endl;
cout << tmp[0].str << endl;
i = 1;
while (tmp[i].c == tmp[0].c && i < e){
cout << tmp[i].str << endl;
i++;
}
cout << endl;
}
system("pause");
}
/*
2 2
aa
aba
aaa abaa
aba aaaa abaaad
*/
poj 1598 Excuses, Excuses!
最新推荐文章于 2022-02-25 19:38:17 发布