题目链接:
由于是可以和 \(T\) 的多个字符串相同而仅计数一次,考虑把 \(T\) 中的字符串用 \(\rm set\) 存储已达到去重的目的。
注:\(\rm set\) 的 \(\rm count\) 返回 \(1\) 表示找到了该元素,返回 \(0\) 则说明没找到。
#include <bits/stdc++.h>using i64 = long long;int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int N, M;std::cin >> N >> M;std::vector<std::string> S(N);for (int i = 0; i < N; i++) {std::cin >> S[i];}std::set<std::string> T;for (int i = 0; i < M; i++) {std::string t;std::cin >> t;T.insert(t);}int ans = 0;for (auto s : S) {ans += T.count(s.substr(3));}std::cout << ans << "\n";return 0;
}