看到每一单词在同一句话中出现多次感动值不叠加
,一眼想到 ( ext{set})。
首先将词汇列表中的单词存储起来,我用的是 ( ext{set})。
对于每一个句子的单词,我们可以先判断它是否是词汇列表中的单词,然后将它加入一个 ( ext{set}) 中,如果扫描到句号就将答案加上 ( ext{set}) 的大小,然后清空 ( ext{set}) 。
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d
", __FUNCTION__, __LINE__)
#define itn int
#define gI gi
using namespace std;
typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;
inline int gi()
{
int f = 1, x = 0; char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return f * x;
}
inline LL gl()
{
LL f = 1, x = 0; char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return f * x;
}
int n, ans;
string xsl, pp;
set <string> td, kk;
int main()
{
//freopen("1.in", "r", stdin);
//freopen(".out", "w", stdout);
n = gi();
for (int i = 1; i <= n; i+=1)
{
cin >> xsl;
int len = xsl.size();
for (int j = 0; j < len; j+=1)
{
if (xsl[j] >= 'A' && xsl[j] <= 'Z') xsl[j] = xsl[j] - 'A' + 'a';
}
td.insert(xsl);
}
char c = getchar();
xsl = "";
while (~scanf("%c", &c))
{
//puts("!");
if (c == '
') break;
if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a';
if (c >= 'a' && c <= 'z') xsl = xsl + c;
else
{
if (xsl != "")
{
if (td.find(xsl) != td.end()) kk.insert(xsl);
xsl = "";
}
if (c == '.')
{
ans += kk.size(), kk.clear();
}
}
}
printf("%d
", ans);
return 0;
}