-
Notifications
You must be signed in to change notification settings - Fork 0
/
1047.cpp
63 lines (54 loc) · 1.11 KB
/
1047.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
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string>
using namespace std;
vector<int> courses[2505];
// ½¨Á¢student nameºÍintÒ»Ò»¶ÔÓ¦¹Øϵ
// each contains a student's name (3 capital English letters plus a one-digit number)
int hashName(const char *name)
{
return (name[0]-'A')*26*26*10 + (name[1]-'A')*26*10 + (name[2]-'A')*10 + (name[3]-'0');
}
void rhashName_print(int id)
{
char name[5];
name[4] = '\0';
name[3] = id%10 + '0';
id /= 10;
name[2] = id%26 + 'A';
id /= 26;
name[1] = id%26 + 'A';
id /= 26;
name[0] = id%26 + 'A';
printf("%s\n", name);
}
int main()
{
int N, K;
int hname, index, num;
char name[5];
scanf("%d %d", &N, &K);
for (int i = 0; i != N; ++i)
{
scanf("%s", name);
scanf("%d", &num);
hname = hashName(name);
for (int j = 0; j != num; ++j)
{
scanf("%d", &index);
courses[index].push_back(hname);
}
}
for (int i = 1; i <= K; ++i)
{
printf("%d %d\n", i, courses[i].size());
sort(courses[i].begin(), courses[i].end());
for (int j = 0; j != courses[i].size(); ++j)
{
rhashName_print(courses[i][j]);
}
}
system("pause");
return 0;
}