一、技术总结

  1. 首先题目要看清湖,提出的条件很关键,比如for循环的终止条件,特别注意。
  2. 还有这个题目主要考虑到vector的使用,还有注意一定要加上using namespace std;
  3. 输出格式,题目中如果没有要求什么最后一行不能有空格什么的,就不要画蛇添足,按照正常的换行就行。
  4. 这里采用的是先使用二维字符串数组存储名字,然后名字也有编号,使用这个编号来记录每个课程中选取的学生,巧妙的避免了要记录下字符串的尴尬局面。然后再开辟一个vector容器来记录课程中选课学生的编号,最后排序即可。
  5. 如果很大的字符串存储,不要使用string,要使用char数组,可以是二维的。然后如果要比较字符串的大小,按字母从小到大使用cmp如下:
bool cmp(int a, int b){
//这里是按字符串从小到大,如果相反改变下面中小于号为大于号即可,同时stu是提前声明的全局变量二维字符串数组
return strcmp(stu[a], stu[b]) < 0;
}

二、参考代码

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 40010;
const int K = 2510;
char stu[N][5];
vector<int> q[K];
bool cmp(int a, int b){
return strcmp(stu[a], stu[b]) < 0;
}
int main(){
int n,k;
scanf("%d%d", &n, &k);
int num = 0;
int course = 0;
for(int i = 0; i < n; i++){
scanf("%s %d", stu[i], &num);
for(int j = 0; j < num; j++){
scanf("%d", &course);
q[course].push_back(i);
}
}
for(int i = 1; i <= k; i++){
sort(q[i].begin(), q[i].end(), cmp);
printf("%d %d\n", i, q[i].size());
for(int j = 0; j < q[i].size(); j++){
printf("%s\n", stu[q[i][j]]);
}
}
return 0;
}

A1047 Student List for Course (25 分)的更多相关文章

  1. 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 ...

  2. 1047 Student List for Course (25分)

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

  3. 【PAT甲级】1047 Student List for Course (25 分)

    题意: 输入两个正整数N和K(N<=40000,K<=2500),接下来输入N行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号.输出每门课程有多少学生选择并按字典序输 ...

  4. PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*

    1039 Course List for Student (25 分)   Zhejiang University has 40000 students and provides 2500 cours ...

  5. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  6. 1109 Group Photo (25 分)

    1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of fo ...

  7. 1012 The Best Rank (25 分)

    1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...

  8. 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  9. A1083 List Grades (25)(25 分)

    A1083 List Grades (25)(25 分) Given a list of N student records with name, ID and grade. You are supp ...

随机推荐

  1. 最近公共祖先(LCA)基础模板(倍增法)

    之前在澡堂学过这么个东西,听课时理解非常透彻,然后做题时是这种状态: 因为并没有切板子题,最近切掉以后看同桌,他默默地说了一句话: 我是什么时候A的来着... 我当时就心态爆炸... 现在来进行简单整 ...

  2. OpenFOAM——过渡管中的湍流

    本算例来自<ANSYS Fluid Dynamics Verification Manual>中的VMFL016:Turbulent Flow in a Transition Duct 一 ...

  3. csrf攻击与csrf防御

    CSRF(Cross-site request forgery)跨站请求伪造,也被称为“One Click Attack”或者Session Riding,通常缩写为CSRF或者XSRF,是一种对网站 ...

  4. CentOS7下rsync服务端与Windows下cwRsync客户端实现数据同步配置方法

    最近需求想定期备份服务器d盘的数据到Linux服务器上面,做个笔记顺便写下遇到的问题 以前整过一个win下的cwrsync(客户端)+rsync(服务端:存储)的bat脚本 和整过一个Linux下的r ...

  5. Saiku默认给数据类型的数据添加小数点问题处理(三十一)

    Saiku默认给数据类型的数据添加小数点问题处理 不知道大家有没有遇到过saiku定义的维度信息,数据类型时 展示出来的数据会自动加上 .0的后缀. 比如我定义了一个维度为 年, 在数据库中为 int ...

  6. postman测试文件上传接口教程

    postman是一个很好的接口测试软件,有时候接口是Get请求方式的,肯定在浏览器都可以测了,不过对于比较规范的RestFul接口,限定了只能post请求的,那你只能通过工具来测了,浏览器只能支持ge ...

  7. 使用openpyxl模块进行封装,高效处理excel测试数据

    from openpyxl import load_workbook from scripts.handle_config import conf from scripts.constants imp ...

  8. MySQL数据库查询所有表名

    查找指定库中所有表名 select table_name from information_schema.tables where table_schema='db_name'; 注:替换db_nam ...

  9. Web前端——表单提交和Js添加选项

    表单 表单提交 表单提交之后会将表单的数据以get或post方式,传送到action要打开的页面 方式1: 使用提交按钮 <form action="" method=&qu ...

  10. Python爬取十四万条书籍信息告诉你哪本网络小说更好看

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: TM0831 PS:如有需要Python学习资料的小伙伴可以加点击 ...