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
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;
char name[][];
vector<int> course[];
bool cmp(int a, int b){
return strcmp(name[a], name[b]) < ;
}
int main(){
int N, K, Ni;
scanf("%d%d", &N, &K);
for(int i = ; i < N; i++){
scanf("%s", name[i]);
scanf("%d", &Ni);
for(int j = ; j < Ni; j++){
int cId;
scanf("%d", &cId);
course[cId].push_back(i);
}
}
for(int i = ; i <= K; i++){
int len = course[i].size();
printf("%d %d\n", i, len);
sort(course[i].begin(), course[i].end(), cmp);
for(int j = ; j < len; j++){
printf("%s\n", name[course[i][j]]);
}
}
cin >> N;
return ;
}

总结:

1、在开二维数组占用空间过大的情况下,可以使用vector<int> num[N],由于初始时每一个vector内均无元素,所以数组可以开的很大。

2、本题需要以课程为主体,存储选课的学生,如果对于每一门课都存储选课的学生名字的话,需要使用string存在vector数组中,需要char[] 与string的互转,比较浪费时间。可以直接把名字作为data存储下来,在vector数组中仅仅存储data的下标即可。 在名字字典序排序时可以用如下方法,用字符串下标代替字符串进行排序

bool cmp(int a, int b){
  return strcmp(name[a], name[b]) < 0;
}

3、sort对vector排序时,区间应填入:sort(vec.begin(), vec.end(), cmp);

A1047. Student List for Course的更多相关文章

  1. PAT甲级——A1047 Student List for Course

    Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course ...

  2. 【算法笔记】A1047 Student List for Course

    https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960 题意 给出每个学生的选课情况,输出每节课选课 ...

  3. A1047 Student List for Course (25 分)

    一.技术总结 首先题目要看清湖,提出的条件很关键,比如for循环的终止条件,特别注意. 还有这个题目主要考虑到vector的使用,还有注意一定要加上using namespace std; 输出格式, ...

  4. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  5. java.io.NotSerializableException: test.io.file.Student

    java.io.NotSerializableException: test.io.file.Student    at java.io.ObjectOutputStream.writeObject0 ...

  6. 使用java反射机制编写Student类并保存

    定义Student类 package org; public class Student { private String _name = null; ; ; public Student() { } ...

  7. 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  8. The constructor User.Student(String, String, String) is not visible

    项目:蒙文词语检索 日期:2016-05-01 提示:The constructor User.Student(String, String, String) is not visible 出处:Db ...

  9. Java-集合-第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList(); l

    第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; ...

随机推荐

  1. 【CV】ICCV2015_Learning Temporal Embeddings for Complex Video Analysis

    Learning Temporal Embeddings for Complex Video Analysis Note here: it's a review note on novel work ...

  2. Linux内核分析——第四章 进程调度

    第四章 进程调度 4.1 多任务 1.多任务操作系统就是能同时并发的交互执行多个进程的操作系统. 2.多任务操作系统使多个进程处于堵塞或者睡眠状态,实际不被投入执行,这些任务尽管位于内存,但是并不处于 ...

  3. 网络:LVS负载均衡原理

    LB集群的架构和原理很简单,就是当用户的请求过来时,会直接分发到Director Server上,然后它把用户的请求根据设置好的调度算法,智能均衡地分发到后端真正服务器(real server)上.为 ...

  4. servlet请求转发

    来源:http://www.2cto.com/kf/201610/554591.html 请求转发:Servlet(源组件)先对客户请求做一些预处理操作(数据处理),然后把请求转发给其他Web组件(目 ...

  5. Centos wget命令 not found解决方法

    如果已经有了yun源,则可通过yun源命令来安装wget. 如下所示: 2.yum安装yum -y install wget 即可安装:

  6. Mock.js的简单使用

    Mock.js 提供的种类有: 步骤: 首先安装:cnpm install mockjs 创建一个mock.js的文件,写好需要引入的数据格式 在main.js中引入mock.js文件: requir ...

  7. linux和Mac上安装composer

    使用命令行方式,可以直接使用下面的命令,顺序执行: php -r "copy ('https://getcomposer.org/installer','composer-setup.php ...

  8. 转载 loadrunner的一些问题解决

    sckOutOfMemory 7 内存不足  sckInvalidPropertyValue 380 属性值不效  sckGetNotSupported 394 属性不可读  sckGetNotSup ...

  9. 软件工程_9th weeks

    PSP DATE START_TIME END_TIME EVENT TYPE       TIME 4.30-5.3 5:30 4:00 旅游 娱乐       72h 5.3 14:00 17:0 ...

  10. Check failed: status == CUBLAS_STATUS_SUCCESS (11 vs. 0) CUBLAS_STATUS_MAPPING_ERROR

    I0930 21:23:15.115576 30918 solver.cpp:281] Learning Rate Policy: multistepF0930 21:23:17.263314 310 ...