不用hash映射 就要用unordered_map 而且cin还要改成scanf cout改了更好
#include<vector>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<set>
#include<map>
using namespace std;
int main()
{
unordered_map<string, vector<int>>student;
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++)
{
int a, b;
scanf("%d %d", &a, &b);
for (int j = 0; j < b; j++)
{
string s;
s.resize(4);
scanf("%s", &s[0]);
student[s].push_back(a);
}
}
for (int i = 0; i < n; i++)
{
string s;
s.resize(4);
scanf("%s", &s[0]);
auto it=student.find(s);
sort(student[s].begin(), student[s].end());
if (it == student.end())
{
cout << s << " " << "0";
}
else
{
cout << it->first << " " << student[s].size();
for (auto it = student[s].begin(); it != student[s].end(); it++)
cout << " " << *it;
}
cout << endl;
}
}