#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int id = 1;
map<string, int> strtoi;
map<int, string> itostr;
int fun(string s){
if (strtoi[s] == 0){
strtoi[s] = id;
itostr[id] = s;
return id++;
}
else return strtoi[s];
}
int main(){
string stu;
int n, k, course, num, que;
vector<int> list[50000];
cin >> n >> k;
for (int i = 0; i < k; i++){
cin >> course >> num;
for (int j = 0; j < num; j++){
cin >> stu;
list[fun(stu)].push_back(course);
}
}
for (int i = 0; i < n; i++){
cin >> stu;
que = fun(stu);
sort(list[que].begin(), list[que].end());
cout << itostr[que] << " " << list[que].size();
if (list[que].size() == 0) cout << endl;
else{
for (int j = 0; j < list[que].size(); j++){
printf(" %d", list[que][j]);
}
printf("\n");
}
}
}
PAT甲級1039
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.