1047. Student List for Course (25)
Zhejiang University has 40000 students and provides 2500 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 (<=40000), the total number of students, and K (<=2500), 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 (<=20) 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
思路:建立2500个课程的vector,存放学生的姓名(最开始的时候用了list,超时;不要用c++的cin和cout)
#include <iostream>
#include"stdio.h"
#include"stdlib.h"
#include"vector"
#include"string"
#include"algorithm" using namespace std; int main()
{
long N;
int K,C;
cin>>N>>K;
scanf("%ld%d",&N,&N); int order;
vector<string> l[2501]; string name;
for(int i=1;i<=N;i++){
cin>>name;
scanf("%d",&C);
for(int j=1;j<=C;j++){
scanf("%d",&order);
l[order].push_back(name);
}
} for(int i=1;i<=K;i++){
int size = l[i].size();
printf("%d %d\n",i,size);
if(size)
{
sort(l[i].begin(),l[i].end()); vector<string>::iterator iter;
for(iter=l[i].begin();
iter<l[i].end();
iter++){
printf("%s\n",(*iter).c_str());
}
}
}
return 0;
}
1047. Student List for Course (25)的更多相关文章
- PAT 解题报告 1047. Student List for Course (25)
1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...
- 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 ...
- 1047 Student List for Course (25分)
Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course ...
- PAT (Advanced Level) 1047. Student List for Course (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲级题解-1047. Student List for Course (25)-排序
一开始是建立了course[2501][40001]数组,存储每节课的学生编号然后for循环两层输出,但这样复杂度为O(2500*40000),也很明显导致最后时间超时后来发现最多40000学生,每个 ...
- 【PAT甲级】1047 Student List for Course (25 分)
题意: 输入两个正整数N和K(N<=40000,K<=2500),接下来输入N行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号.输出每门课程有多少学生选择并按字典序输 ...
- PAT 1047 Student List for Course[一般]
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cours ...
- 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960 Zhejiang University ha ...
随机推荐
- url地址中 "&" "/"等符号的转义处理(转)
URL出现了有+,空格,/,?,%,#,&,=等特殊符号的时候,可能在服务器端无法获得正确的参数值,如何是好? 解决办法:将这些字符转化成服务器可以识别的字符,对应关系如下: URL中的特殊字 ...
- T-SQL 高级查询
基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 selec ...
- Javaweb三大组件之过滤器filter
Filter的三个方法 void init(FilterConfig):在Tomcat启动时被调用: void destroy():在Tomcat关闭时被调用: void doFilter(Servl ...
- Sublime text追踪函数插件:ctags
转自:http://blog.csdn.net/xxhsu/article/details/30766675 一.下载: 1)http://ctags.sourceforge.net/ 2)http: ...
- JQuery学习之操作CSS
样式表: .important{ font-weight:bold; font-size:xx-large; } .blue{ color:blue; } 1.addClass():向被选元素添加一个 ...
- 《DSP using MATLAB》示例Example4.11
代码: b = [1, 0]; a = [1, -0.9]; % %% ---------------------------------------------- %% START a determ ...
- DuckHunter Attacks
DuckHunter Attacks DuckHunter Attacks是从USB Rubber Ducky (USB橡皮鸭)发展过来的HID攻击方式.USB Rubber Ducky是从201 ...
- 分享Kali Linux 2016.2第41周镜像虚拟机
分享Kali Linux 2016.2第41周镜像虚拟机该虚拟机使用Kali Linux 2016.2第41周镜像文件安装而成,系统已经更新到10月12日.里面已经进行如下配置:(1)设置官方软件源( ...
- css3 -- 颜色与不透明度
1.opacity: opacity的值会被它的所有子元素继承,也就是说不可能让一个元素比他的父元素更加不透明,但你可以让他变得更透明点 Firefox Webkit Opera支持,注意IE 2 ...
- 分布式缓存技术memcached学习(一)——linux环境下编译memcahed
安装依赖工具 [root@localhost upload]# yum install gcc make cmake autoconf libtool 下载并上传文件 memcached 依 ...