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. 如何查看CRM WebUI,C4C和Hybris里的页面技术信息

    CRM 在WebClient UI页面上按F2,就能看到页面的技术信息, 可以找到当前页面是哪一个BSP component实现的: C4C 在浏览器url里添加debugMode=true,然后按住 ...

  2. java的图形界面初学惯用

    1.单一界面的创建 public void mainFrame() { HashMap<String, Component> views = new HashMap<String, ...

  3. window.onload中调用函数报错的问题

    今天练习js,忽然遇到了一个问题,就是window.onload加载完成后,调用其中的函数会报错, 上一段简单的代码: 报错信息: 报错原因: 当window.onload加载完成后,第一个alert ...

  4. javascript:理解DOM事件

    首先,此文不讨论繁琐细节,但是考虑到读者的心灵感受,本着以积极向上的心态,在此还是会列举示例说明. ​标题为理解DOM事件,那么在此拿一个简单的点击事件为例,希望大家看到这个例子后能触类旁通. DOM ...

  5. innobackupex实现对MySQL的增量备份与还原

    备份增量备份是基于完整备份的,所以我们需要先做一次完整备份: innobackupex --defaults-file=/etc/my.cnf --user root --password cheng ...

  6. 【转载】LCT题单

    本篇博客的题单转载自FlashHu大佬的博客:LCT总结--应用篇(附题单)(LCT). 关于\(LCT\)可以查看这篇博客:\(LCT\)入门. 这里面有些题解的链接是空链接,尚未补全. 维护链信息 ...

  7. 导航条(Navbar)

    1.添加.navbar-fixed-top类可以让导航条固定的页面的顶部,固定的导航条会遮住页面上其它的内容,除非给body元素设置padding,导航条默认高度为50px ,因此可以给body元素设 ...

  8. ML.NET技术研究系列1-入门篇

    近期团队在研究机器学习,希望通过机器学习实现补丁发布评估,系统异常检测.业务场景归纳一下: 收集整理数据(发布相关的异常日志.告警数据),标识出补丁发布情况(成功.失败) 选择一个机器学习的Model ...

  9. Finders Keepers-freecodecamp算法题目

    Finders Keepers 1.要求 写一个 function,它遍历数组 arr,并返回数组中第一个满足 func 返回值的元素. 举个例子,如果 arr 为 [1, 2, 3],func 为 ...

  10. mysql 报错 Operand should contain 1 column(s)

    报错 Operand should contain 1 column(s) 原因 select 后面加了 () select (x,x,x)