-
Notifications
You must be signed in to change notification settings - Fork 0
/
A1039.cpp
44 lines (41 loc) · 880 Bytes
/
A1039.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 40010;
const int M = 26*26*26*10 + 1;
vector<int> selectCourse[M];
int getID(char name[]){
int id = 0;
for(int i = 0; i < 3; i++){
id = id*26 + (name[i] - 'A');
}
id = id*10 + (name[3] - '0');
return id;
}
int main()
{
char name[5];
int n, k;
scanf("%d %d", &n, &k);
for(int i = 0; i< k; i++){
int course, x;
scanf("%d %d", &course, &x);
for(int j = 0; j < x; j++){
scanf("%s", name);
int id = getID(name);
selectCourse[id].push_back(course);
}
}
for(int i = 0; i < n; i++){
scanf("%s", name);
int id = getID(name);
sort(selectCourse[id].begin(), selectCourse[id].end());
printf("%s %d", name, selectCourse[id].size());
for(int j = 0; j < selectCourse[id].size(); j++){
printf(" %d", selectCourse[id][j]);
}
printf("\n");
}
return 0;
}