AcWing 1523. 学生课程列表
原题链接
中等
作者:
Laity_3
,
2021-08-22 16:24:28
,
所有人可见
,
阅读 222
#include <bits/stdc++.h>
using namespace std;
const int N = 40010, K = 2510;
struct student {
string name;
}stu[N];
int n, k;
unordered_map<string, vector<int> > m;
int main() {
cin >> n >> k;
for (int i = 0; i < k; i++) {
int id, num;
cin >> id >> num;
while (num--) {
string name;
cin >> name;
m[name].push_back(id);
}
}
int cnt = 0;
int n1 = n;
while (n--) {
string s;
cin >> s;
cnt++;
if (m.count(s)) {
cout << s << ' ' << m[s].size() << ' ';
sort(m[s].begin(), m[s].end());
for (int i = 0; i < m[s].size() - 1; i++)
cout << m[s][i] << ' ';
cout << m[s][m[s].size() - 1];
if (cnt != n1)
cout << endl;
}
else if (!m.count(s))
{
cout << s << ' ' << 0;
if (cnt != n1) cout << endl;
}
}
}