参考代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 100010;
int n, m;
string s;
set<string> rs;
string tolower(string s)
{
int n = s.size();
for (int i = 0; i < n; i++) {
if (s[i] < 'a') s[i] = char(s[i] + 'a' - 'A');
}
return s;
}
void solve()
{
getline(cin, s);
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
rs.insert(t);
}
int cnt = 0;
n = s.size();
for (int i = 0; i < n;) {
if (s[i] == ' ') i++;
else if (s[i] == ',' or s[i] == '.' or s[i] == '!' or s[i] == '?') i++;
else if (s[i] == '\r' or s[i] == '\n') i++;
else {
string t = "";
while (i < n and s[i] != ' ' and s[i] != ',' and s[i] != '.' and s[i] != '!' and s[i] != '?') t += s[i++];
t = tolower(t);
if (rs.find(t) == rs.end()) {
cnt++;
rs.insert(t);
}
}
}
cout << cnt << endl;
}
int main()
{
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}