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 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二叉树可以通过给定的一对后序和顺序遍历序列来确定.这是一个简单的标准程序,可以按 ...
随机推荐
- (15)python打包
.py文件在没有安装python软件的电脑上是不能被执行的
- mysql中的字符串截取和替换
-- 替换 replace(字段名,"需要替换的字符","替换的字符") mysql里replace不支持正则匹配 mysql> set @needRep ...
- 海量数据解决思路之Hash算法
海量数据解决思路之Hash算法 一.概述 本文将粗略讲述一下Hash算法的概念特性,里边会结合 分布式系统负载均衡 实例对Hash的一致性做深入探讨.另外,探讨一下Hash算法在海量数据处理方案中 ...
- 适AT maven多个子项目、父项目之间的引用问题
适AT maven多个子项目.父项目之间的引用问题 在项目时用到maven管理项目,在一个就项目的基础上开发新的项目:关于子项目和父项目,子项目与子项目之间的调用问题,发现自己存在不足,以下是自己 ...
- POJ-2499-Binary Tree-思维题
Background Binary trees are a common data structure in computer science. In this problem we will loo ...
- 程序员如何面对 HR 面试的 40 个问题!
讲一个身边朋友亲身经历的故事吧. 一个技术非常牛的朋友去阿里面试,成功通过了几轮技术车轮战,最后躺在了 HR 面上...所以,尽管你技术再牛逼,你回答不好 HR 的问题,赢得不了 HR 的认可,你最终 ...
- Censored! POJ - 1625 AC自动机+大数DP
题意: 给出一n种字符的字典,有p个禁用的单词, 问能组成多少个不同的长度为m的合法字符串.(m<=50) 题解: 是不是个我们之前做的题目非常非常像,题意都一样. 直接将上次写的AC自动机+矩 ...
- nodejs和vuejs的关系
转自:https://blog.csdn.net/myKurt/article/details/79914078 nodejs类比Java中:JVM 详述: 就前端来说nodejs具有划时代的意义, ...
- 微软云数据库SQL Azure
- css实现图文混排
css实现图文混排 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...