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. Flask-sqlalchemy 语法总结

    Flask-sqlalchemy 语法总结 ** DDLdb.create_all() :创建实体表db.drop_all(): 删除表 1)插入表Db.session.add(user) #user ...

  2. Bash : IO 重定向

    标准输入/输出(standard I/O)可能是软件设计原则里最重要的概念了.这个概念就是:程序应该有数据的来源端.数据的目的端(输出结果的地方)已经报告问题的地方,它们分别被称为标准输入(stand ...

  3. Microsoft Office软件自定义安装目录

    Microsoft Office安装时不能手动设置安装目录,本文描述通过修改注册表的方式自定义安装目录 1.同时按下快捷键 win + r 启动运行 2.输入 regedit 打开注册表 3.找到   ...

  4. SKINNY加密算法详解(无代码,仅加密)

    原作者论文请参考<The SKINNY Family of Block Ciphers and Its Low-Latency Variant MANTIS> 地址为:https://li ...

  5. @Scheduled 定时

    此文章记录在spring boot项目中的使用 1,在项目的启动类中加注解@EnableScheduling,表示此项目可以进行定时 @SpringBootApplication @EnableSch ...

  6. jisuanqi

    1.jisuanqi 2.https://github.com/12wangmin/text/tree/master 3.计算截图 7+8 清除 4.总结 通过课程设计,主要要达到两个目的,一是检验和 ...

  7. ECharts设置y轴显示

    参考地址:https://www.w3cschool.cn/echarts_tutorial/echarts_tutorial-no3h2cul.html yAxis: { type: 'value' ...

  8. Java实现小学四则运算练习系统(UI)

    github项目地址 :https://github.com/feser-xuan/Arithmetic_test3_UI 小伙伴的博客链接:http://www.cnblogs.com/fukang ...

  9. Setting Tomcat Heap Size (JVM Heap) in Eclipse

    this article picked from:http://viralpatel.net/blogs/setting-tomcat-heap-size-jvm-heap-eclipse/ Rece ...

  10. node多文件处理方法

    let events = require('events'); let fs = require('fs'); // 将readfile封装成一个方法 多文件处理  function fnreadFi ...