词频统计 第33次CCF-CSP计算机软件能力认证
用来一次性填充
#include<algorithm>
fill(flag.begin(),flag.end(),false);
#include<bits/stdc++.h>
using namespace std;
int n, m;
vector<bool> flag(110, false);
int main() {
cin >> n >> m;
map<int, int> xx;//xx[i]代表第i个单词出现在几篇文章
map<int, int> yy;//yy[i]代表第i个单词出现多少次
for (int i = 0; i < n; i++) {
int l;
cin >> l;
//遍历当前文章的每个词
fill(flag.begin(), flag.end(), false);
for (int j = 0; j < l; j++) {
int word;
cin >> word;
if (flag[word] == false) {
xx[word]++;
flag[word] = true;
}
yy[word]++;
}
}
for (int i = 1; i <= m; i++) {
cout << xx[i] << " " << yy[i] << endl;
}
return 0;
}