借放程式碼,這題找到一個很酷的東東來解,就是 set_intersection,他可以用來找一樣的東西
//AC e465 f605 i399 k918 k900 k920 k921 d074
//WA d098
#include <bits/stdc++.h>
#define fast_as_a_fuckboy ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main() {
fast_as_a_fuckboy
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
set<int> s1, s2;
int num;
for (int j = 0; j < m; j++) {
cin >> num;
s1.insert(num);
}
for (int j = 0; j < m; j++) {
cin >> num;
s2.insert(num);
}
// 找交集
vector<int> intersection;
set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), back_inserter(intersection));
// 輸出交集的大小
cout << intersection.size() << "\n";
}
return 0;
}