https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960

Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 numbers: N (≤), the total number of students, and K (≤), the total number of courses. Then N lines follow, each contains a student's name (3 capital English letters plus a one-digit number), a positive number C (≤) which is the number of courses that this student has registered, and then followed by C course numbers. For the sake of simplicity, the courses are numbered from 1 to K.

Output Specification:

For each test case, print the student name lists of all the courses in increasing order of the course numbers. For each course, first print in one line the course number and the number of registered students, separated by a space. Then output the students' names in alphabetical order. Each name occupies a line.

Sample Input:

10 5
ZOE1 2 4 5
ANN0 3 5 2 1
BOB5 5 3 4 2 1 5
JOE4 1 2
JAY9 4 1 2 5 4
FRA8 3 4 2 5
DON2 2 4 5
AMY7 1 5
KAT3 3 5 4 2
LOR6 4 2 4 1 5

Sample Output:

1 4
ANN0
BOB5
JAY9
LOR6
2 7
ANN0
BOB5
FRA8
JAY9
JOE4
KAT3
LOR6
3 1
BOB5
4 7
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1
5 9
AMY7
ANN0
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1

代码:

#include <bits/stdc++.h>
using namespace std; int N, K; struct Node{
string name;
int num;
}node[40010]; struct Class{
vector<string> id;
int cnt;
}cclass[2510]; int main() { scanf("%d%d", &N, &K);
for(int i = 1; i <= N; i ++) { cin >> node[i].name;
scanf("%d", &node[i].num); for(int j = 1; j <= node[i].num; j ++) {
int x;
scanf("%d", &x);
cclass[x].cnt ++;
cclass[x].id.push_back(node[i].name);
}
} for(int i = 1; i <= K; i ++) {
printf("%d %d\n", i, cclass[i].cnt);
sort(cclass[i].id.begin(), cclass[i].id.end());
for(int j = 0; j < cclass[i].cnt; j ++)
printf("%s\n", cclass[i].id[j].c_str());
}
return 0;
}

  

PAT 甲级 1047 Student List for Course的更多相关文章

  1. PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)

    1047 Student List for Course (25 分)   Zhejiang University has 40,000 students and provides 2,500 cou ...

  2. PAT甲级——A1047 Student List for Course

    Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course ...

  3. 1047 Student List for Course ——PAT甲级真题

    1047 Student List for Course Zhejiang University has 40,000 students and provides 2,500 courses. Now ...

  4. PAT 1047 Student List for Course[一般]

    1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cours ...

  5. PAT 解题报告 1047. Student List for Course (25)

    1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...

  6. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  7. 【转载】【PAT】PAT甲级题型分类整理

    最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...

  8. PAT 甲级真题题解(1-62)

    准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format  模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...

  9. PAT甲级目录

    树(23) 备注 1004 Counting Leaves   1020 Tree Traversals   1043 Is It a Binary Search Tree 判断BST,BST的性质 ...

随机推荐

  1. oc语言基础整理

    objc.h---------------- typedef struct objc_class *Class; struct objc_object { Class isa  OBJC_ISA_AV ...

  2. IBM中国

    https://www.ibm.com/developerworks/cn/linux/l-memory/

  3. 项目开发中dev、test和prod是什么意思

    开发环境(dev):开发环境是程序猿们专门用于开发的服务器,配置可以比较随意,为了开发调试方便,一般打开全部错误报告. 测试环境(test):一般是克隆一份生产环境的配置,一个程序在测试环境工作不正常 ...

  4. kubernetes-控制器Deployment和DaemonSet(八)

    Pod与controllers的关系 •controllers:在集群上管理和运行容器的对象•通过label-selector相关联•Pod通过控制器实现应用的运维,如伸缩,升级等 控制器又称工作负载 ...

  5. "segmentation fault " when "import tensorflow as tf"

    https://github.com/tensorflow/tensorflow/issues/2034

  6. cocoapods 类库管理利器

    作为iOS开发者,第三方类库的使用是最经常的,但鉴于第三方类库的不断更新以及其可能需要依存其他类,如果要使用最新版那么我们需要重新下载再添加到项目中,无疑带来一些繁琐的麻烦,那么现在这里就有一款能解决 ...

  7. es6中的类及es5类的实现

    目录 类的特点 类的特点 1.类只能通过new得到 在es6中类的使用只能是通过new,如果你将它作为一个函数执行,将会报错. //es6的写法 class Child { constructor() ...

  8. 牛客NOIP提高组R1 C保护(主席树)

    题意 题目链接 Sol Orz lyq 我们可以把一支军队(u, v)拆分为两个(u, lca)和(v, lca) 考虑一个点x,什么时候军队对它有贡献,肯定是u或v在他的子树内,且lca在他的子树外 ...

  9. nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument解决

    先附上错误信息: (myblog) root@Dapeng:/home/uwsgi# service nginx status ● nginx.service - A high performance ...

  10. python字典按照k,v来排序

    按照 k 排序 按照 v 排序