题意:给出一系列要忽略的单词,这些单词以外的单词都看作关键字。然后给出一些标题,找出标题中所有的关键字,然后按这些关键字的字典序给标题排序。
注意两点:相同关键字出现在不同标题中,出现在输入较前位置的标题排在前面(从样例数据可以看出,而且multimap也正是这么做的);同一个关键字在一个标题中出现多次,关键字位于较前位置的排在前面(从左向右扫描的话就没有问题)。
这题略坑,功力不够参考了心如止水大神的题解orz。
代码:
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <cctype>
#include <algorithm>
using namespace std;
const int maxn = 220;
int main() {
string k, st;
int a = 0;
set<string> o;
multimap<string, string> r;
while (cin >> k && k != "::")
o.insert(k);
getchar();
while (getline (cin, st)) {
for (int i = 0; i < st.size(); i++)
st[i] = tolower(st[i]);
for (int i = 0; i < st.size(); i++) {
if (!isalpha(st[i])) continue;
string t;
int rec = i;
while (i < st.size() && isalpha(st[i]))
t += st[i++];
if (!o.count(t)) {
for (int j = 0; j < t.size(); j++)
t[j] = toupper(t[j]);
string temp = st;
temp.replace(rec, t.size(), t);
r.insert(make_pair(t, temp));
}
}
}
for (multimap<string, string>::iterator i = r.begin(); i != r.end(); i++)
cout << i -> second << endl;
return 0;
}