PAT甲级——A1047 Student List for Course
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 <iostream>
#include <vector>
#include <string>
#include <algorithm>
//题目不难,不过数据量很大,很容易超时。可以定义一个string数组name按读入顺序存储读取的名字字符串,然后定义一个长度为K + 1的vector<int>的数组course,其数组下标存储课程号,数组元素存储选修该课程的学生的名字在name中的下标。在输出时对course中的数组元素按要求排序,然后输出即可。
//注意点
//排序时直接对字符串进行排序非常消耗时间,可以利用字符串的下标代替字符串本身进行排序 using namespace std;
int N, K, C;
int main()
{
cin >> N >> K;
vector<vector<int>>courses(K + );
vector<string>name(N + );
int num;
for (int i = ; i < N; ++i)
{
cin >> name[i] >> C;
for (int j = ; j < C; ++j)
{
cin >> num;
courses[num].push_back(i);
}
}
for (int i = ; i <= K; ++i)
{
if (courses[i].size() == )continue;
cout << i << " " << courses[i].size() << endl;
sort(courses[i].begin(), courses[i].end(), [=](int a, int b) {return name[a] < name[b]; });
for (auto a : courses[i])
cout << name[i] << endl;
}
return ;
}
PAT甲级——A1047 Student List for Course的更多相关文章
- PAT 甲级 1047 Student List for Course
https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960 Zhejiang University ha ...
- 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甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 【转载】【PAT】PAT甲级题型分类整理
最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...
- PAT甲级题分类汇编——排序
本文为PAT甲级分类汇编系列文章. 排序题,就是以排序算法为主的题.纯排序,用 std::sort 就能解决的那种,20分都算不上,只能放在乙级,甲级的排序题要么是排序的规则复杂,要么是排完序还要做点 ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT甲级1131. Subway Map
PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...
- PAT甲级1127. ZigZagging on a Tree
PAT甲级1127. ZigZagging on a Tree 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二叉树可以通过给定的一对后序和顺序遍历序列来确定.这是一个简单的标准程序,可以按 ...
随机推荐
- centos6.4下安装python3.6.1
1.安装编译环境所需包 #yum install zlib-devel bzip2-devel openssl-devel ncurese-devel gcc zlib 安装成功 2.下载源码包 #w ...
- hive 总结三(压缩)
本文参考:黑泽君相关博客 本文是我总结日常工作中遇到的坑,结合黑泽君相关博客,选取.补充了部分内容. 开启 map 输出阶段压缩可以减少 job 中 map 和 Reduce task 间数据传输量. ...
- layui之input里格式验证
form.verify({ title: function(value){ if(value.length < 5){ retu ...
- 08_springboot2.x自定义starter
概述 starter:启动器 1.这个场景需要使用到的依赖是什么? 2.如何编写自动配置 规则: @Configuration //指定这个类是一个配置类 @ConditionalOnXXX //在指 ...
- flexbox属性速览及常见布局实现
CSS3 弹性盒子(Flex Box)弹性盒子是即 CSS2 浮动布局后, CSS3 的一种新的布局模式. CSS3 弹性盒( Flexible Box 或 flexbox),是一种当页面需要适应不同 ...
- 初识OpenCV-Python - 006: 图像的几何变换
本次小节学习了图像的变换,主要应用到如下方法: cv2.resize(), cv2.warpAffine(), cv2.getRotationMatrix2D(), cv2.getAffineTran ...
- springcloud(十六)、feign+hystrix+ribbon+zuul应用案例
在 基于 " sringcloud(十四).ribbon负载均衡策略应用案例 "所有工程的基础上,进行如下操作进行网关设置 1.创建eureka-client-consumer-z ...
- 如何给DropDownListFor设置默认值
1.直接赋值: @Html.DropDownListFor(o => o.ParentId, ViewBag.root as IEnumerable<SelectListItem>, ...
- umount:将文件设备卸载
[root@centos57 ~]# umount /dev/hda1 用设备文件名来卸载 [root@centos57 ~]# umount /aixi 用挂 ...
- Python全栈开发:pymysql
本篇对于Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy pymsql pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb ...