-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathA1047.cpp
56 lines (51 loc) · 1.15 KB
/
A1047.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
#include <cstdio>
#include <vector>
#include <algorithm>
#define MAXN 40000
#define MAXK 2500
using namespace std;
char names[MAXN + 5][5];
vector<int> cou_stu[MAXK + 5]; // course - student table
int cmp_names(char name1[], char name2[])
{
int id1 = 0, id2 = 0;
for (int i = 0; i < 3; i++)
{
id1 = id1 * 26 + name1[i];
id2 = id2 * 26 + name2[i];
}
id1 = id1 * 10 + name1[3];
id2 = id2 * 10 + name2[3];
return id1 - id2;
}
int cmp_id(int i, int j)
{
return cmp_names(names[i], names[j]) < 0;
}
int main()
{
// input
int n, k;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
{
int c;
scanf("%s %d", names[i], &c);
for (int j = 0; j < c; j++)
{
int tmp;
scanf("%d", &tmp);
cou_stu[tmp].push_back(i);
}
}
// sort + output
for (int i = 1; i <= k; i++)
{
int stu_cnt = cou_stu[i].size();
printf("%d %d\n", i, stu_cnt);
sort(cou_stu[i].begin(), cou_stu[i].end(), cmp_id);
for (int j = 0; j < stu_cnt; j++)
printf("%s\n", names[cou_stu[i][j]]);
}
return 0;
}