-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA1039.cpp
More file actions
51 lines (48 loc) · 1.1 KB
/
A1039.cpp
File metadata and controls
51 lines (48 loc) · 1.1 KB
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
45
46
47
48
49
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 10010;
const int M = 26*26*26*10 + 1;
vector<int> selectCourse[M];
int getID(char name[]){//hash函数,将字符串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;
}