-
Notifications
You must be signed in to change notification settings - Fork 0
/
1039.cpp
53 lines (46 loc) · 1.19 KB
/
1039.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
45
46
47
48
49
50
51
52
53
#include <cstdio>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
//由于数据量太大,此解法太慢,无法通过最后一个测试点
//通过构建学生姓名的Hash表可以大大加快查询速度,即以空间换时间
struct course{
set<string> stu;
}cou[2505];
int main(){
int n, k;
scanf("%d %d", &n, &k);
for(int i = 0; i < k; i++){
int num, id;
scanf("%d %d", &id, &num);
for(int j = 0; j < num; j++){
string temp;
cin>>temp;
cou[id].stu.insert(temp);
}
}
bool hashtable[2500] = {false};
int count = 0;
for(int i = 0; i < n; i++){
string name;
cin>>name;
for(int j = 1; j < k + 1; j++){
if(*(cou[j].stu.find(name)) == name){
hashtable[j] = true;
count++;
}
}
printf("%s %d", name.c_str(), count);
for(int j = 1; j < k + 1; j++){
if(hashtable[j] == true){
printf(" %d", j);
}
}
printf("\n");
count = 0;
fill(hashtable + 1, hashtable + k + 1, false);
}
return 0;
}