PAT 甲级 1047 Student List for Course
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的更多相关文章
- 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 ...
- PAT甲级——A1047 Student List for Course
Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course ...
- 1047 Student List for Course ——PAT甲级真题
1047 Student List for Course Zhejiang University has 40,000 students and provides 2,500 courses. Now ...
- PAT 1047 Student List for Course[一般]
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cours ...
- PAT 解题报告 1047. Student List for Course (25)
1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 【转载】【PAT】PAT甲级题型分类整理
最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...
- PAT 甲级真题题解(1-62)
准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format 模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...
- PAT甲级目录
树(23) 备注 1004 Counting Leaves 1020 Tree Traversals 1043 Is It a Binary Search Tree 判断BST,BST的性质 ...
随机推荐
- [Rails学习之路]初识Ruby(二)
继续上次Ruby的学习.接下来就到了Ruby的方法. Ruby的方法与Python仍然很像.使用def定义,可以使用undef取消定义. 在Ruby中,经常可以看见方法后面跟有"?" ...
- iptables (1) 原理
网上看到这个配置讲解得还比较易懂,就转过来了,大家一起看下,希望对您工作能有所帮助. iptables简介 netfilter/iptables(简称为iptables)组成Linux平台下的包过滤防 ...
- 【BZOJ4810】[YNOI2017] 由乃的玉米田(莫队+bitset)
点此看题面 大致题意: 给你一段序列,每次询问一段区间内是否存在两个数的差或和或积为\(x\). 莫队算法 看到区间询问+可以离线,首先想到了莫队啊. 但是,在较短的时间内更新信息依然比较难以实现. ...
- 管道命令'|' 和xargs find命令找到后把所有找到的删除
管道符号,是unix功能强大的一个地方,符号是一条竖线:"|", 用法: command 1 | command 2 他的功能是把第一个命令command 1执行的结果作为comm ...
- Java Web Application使Session永不失效(利用cookie隐藏登录)
在做 Web Application 时,因为 Web Project 有 session 自动失效的问题,所以如何让用户登录一次系统就能长时间运行三个月,就是个问题. 后来,看到 session 失 ...
- Win8如何默认以管理员运行程序
在Win7的时候,关闭UAC,使用自己的用户名,所有程序都是默认以管理员身份运行的. 但是在Win8,关闭UAC,程序不是默认以管理员身份运行的. 在论坛看到的解决方法是:1.用Administrat ...
- 稍微深入点理解C++复制控制【转】
通过一个实例稍微深入理解C++复制控制过程,参考资料<C++ primer>,介绍点基本知识: 1.在C++中类通过特殊的成员函数:复制构造函数.赋值操作符和析构函数来控制复制.赋值和撤销 ...
- 洛谷P1164小A点菜
这也是一道01背包的题 用的方法比较的巧妙.这个动态规划相当于反过来做的,自己理解就知道了.代码很短 #include<bits/stdc++.h> using namespace std ...
- js函数带括号和不带括号赋给对象属性的区别
注意: 1.js为对象添加函数时,不要在函数后面加().一旦加了括号是表示将函数的返回值赋给对象的属性. 例:function test(){ document.writeln("我是js函 ...
- JZOJ 3382. 【NOIP2013模拟】七夕祭
3382. [NOIP2013模拟]七夕祭 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Goto Problem ...