-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.cpp
111 lines (109 loc) · 2.5 KB
/
vector.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* 1039 map<string,vector<int> >
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string.h>
#include <string>
using namespace std;
int main(){
int n,k;
cin>>n>>k;;
map<string,vector<int> > mp;
for(int i=0;i<k;i++){
int course,num;
cin>>course>>num;
for(int j=0;j<num;j++){
string name;
cin>>name;
mp[name].push_back(course);
}
}
char name[10]; //可能要改
while(scanf("%s",&name)!=EOF){
string s(name);
cout<<s<<" "<<mp[s].size();
sort(mp[s].begin(),mp[s].end());
for(int i=0;i<mp[s].size();i++)
cout<<" "<<mp[s][i];
cout<<endl;
}
return 0;
}
*/
/*
// 1039 vector<int> a[m]
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string.h>
#include <string>
using namespace std;
const int m=26*26*26*10+1;
vector<int> v[m];
int getID(string 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(){
int n,k;
cin>>n>>k;;
for(int i=0;i<k;i++){
int course,num;
cin>>course>>num;
for(int j=0;j<num;j++){
string name;
cin>>name;
int id=getID(name);
v[id].push_back(course);
}
}
char name[10]; //可能要改
while(scanf("%s",&name)!=EOF){
string s(name);
int id=getID(s);
cout<<s<<" "<<v[id].size();
sort(v[id].begin(),v[id].end());
for(int i=0;i<v[id].size();i++)
cout<<" "<<v[id][i];
cout<<endl;
}
return 0;
}
*/
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string.h>
#include <string>
using namespace std;
vector<int> v[2510]; //存名字的下标
char na[40010][5]; //名字对应下标
bool cmp(int a,int b){
return strcmp(na[a],na[b])<0;
}
int main(){
int n,k;
cin>>n>>k;;
for(int i=0;i<n;i++){
int num;
scanf("%s%d",&na[i],&num);
for(int j=0;j<num;j++){
int course;
cin>>course;
v[course].push_back(i);
}
}
for(int i=1;i<=k;i++){
printf("%d %d\n",i,v[i].size());
sort(v[i].begin(),v[i].end(),cmp);
for(int j=0;j<v[i].size();j++)
printf("%s\n",na[v[i][j]]);
}
return 0;
}