一、技术总结

  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. [CF1082D]Maximum Diameter Graph

    题目描述 Description Graph constructive problems are back! This time the graph you are asked to build sh ...

  2. __module__和__class__

    目录 一.__module__ 二.__class__ # lib/aa.py class C: def __init__(self): self.name = 'SB' # index.py fro ...

  3. C#开发BIMFACE系列23 服务端API之获取模型数据8:获取模型链接信息

    系列目录     [已更新最新开发文章,点击查看详细] 在Revit等BIM设计工具中可以给模型的某个部位添加链接信息.即类似于在Office Word.Excel 中给一段文字添加本地文件链接或者网 ...

  4. golang数据结构之稀疏数组

    掌握知识: 数组的初始化和赋值 结构体的初始化和赋值 字符串和整型之间的转换以及其它的一些操作 类型断言 读取文件 写入文件 对稀疏数组进行压缩 package main import ( " ...

  5. c#汉字转拼音首字母全拼支持多音字

    1.首先在NuGet安装pingyinConverter 2.下载-安装-引用ChineseChar.dll到项目中 官网了解:http://www.microsoft.com/zh-cn/downl ...

  6. Rpg maker mv角色扮演游戏制作大师简介

    目录 1:简介 2:基本图片展示 3.和js等平台的合作 @(这里写自定义目录标题) 1:简介   <RPG制作大师MV>为<RPG制作大师>的新版本,于18年11月27日登陆 ...

  7. ECharts grid组件离容器的距离

    ECharts grid组件离容器的距离 由 Carrie 创建, 最后一次修改 2017-09-04 grid.left   |   string, number [ default: '10%' ...

  8. hitTest和pointInside如何响应用户点击事件

    hitTest和pointInside如何响应用户点击事件 处理机制 iOS事件处理,首先应该是找到能处理点击事件的视图,然后在找到的这个视图里处理这个点击事件. 处理原理如下: • 当用户点击屏幕时 ...

  9. 【Web】解决简书图片不显示问题“系统维护中,图片暂时无法加载”

    简书不显示图片的解决方法 首次编辑于2019-6-6 最近几天在浏览简书上的文章时,发现图片显示不出来,提示"系统维护中,图片暂时无法加载". 猜测应该是简书由于某种原因暂时屏蔽了 ...

  10. Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the serv

    z 此问题为时区问题,在 JDBC 的连接 url 部分加上 useSSL=true&serverTimezone=UTC 即可.如图