看大家都被卡了好久。。
[codec]
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
using namespace std;
string replace_all(string str,const string old_value,const string new_value)
{
for(string::size_type pos(0); pos!=string::npos; pos+=new_value.length()) {
if((pos=str.find(old_value, pos))!=string::npos)
str.replace(pos,old_value.length(),new_value);
else break;
}
return str;
}
int main() {
vector<string> matches;
int n;
cin >> n;
for(int i=0;i<n;i++) {
string t;
cin >> t;
transform(t.begin(), t.end(), t.begin(), ::tolower);
matches.push_back(t);
}
int g = 0;
string text;
cin.ignore();
getline(cin, text);
transform(text.begin(), text.end(), text.begin(), ::tolower);
text = replace_all(text, ",", " ");
text = replace_all(text, ".", " . ");
text = " " + text + " ";
vector<set<string> > sept;
set<string> a;
for(int i=0;i<text.length();i++) {
while(text[i] == ' ' && i < text.length()) i++;
if(i==text.length()) break;
string t = "";
while(text[i] != ' ') {
t += text[i];
i++;
}
if(t != ".") {
if(t != "") a.insert(t);
} else {
sept.push_back(a);
a = set<string>();
}
}
for(vector<set<string> >::iterator i = sept.begin(); i < sept.end(); i++) {
for(vector<string>::iterator j = matches.begin(); j < matches.end(); j++) {
if((*i).find(*j) != (*i).end()) {
g++;
}
}
}
cout << g << endl;
return 0;
}
[/codec]