1039 Course List for Student 依靠unordered_map<string,set<int>> ans 解决问题。

这次依靠unordered_map<int ,vector<string>> ans;如果vector改成set(自带自排序+去重)最后一个测试点会超时导致无法通过。

所以每次输出结果之前,都要对vector重新排序一次。

STL:unordered_map,vector,sort,string。

#include"iostream"
#include"vector"
#include"unordered_map"
#include"algorithm"
using namespace std; int main() {
int n,k,cNum,index;
scanf("%d%d",&n,&k);
string name;
unordered_map<int ,vector<string>> ans;
for(int i = ; i < n; ++i) {
cin>>name;
scanf("%d",&cNum);
for(int j = ; j < cNum; ++j) {
scanf("%d",&index);
ans[index].push_back(name);
}
}
for(int i = ; i <= k; ++i) {
printf("%d %d\n",i,ans[i].size());
sort(ans[i].begin(),ans[i].end());//对当前vector中的string按字典序排序
for(auto it = ans[i].begin(); it != ans[i].end(); ++it)
printf("%s\n",it->c_str());//string 转char* 输出更快
}
return ;
}

1047 Student List for Course的更多相关文章

  1. PAT 解题报告 1047. Student List for Course (25)

    1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...

  2. PAT 1047 Student List for Course[一般]

    1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cours ...

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

  4. 1047 Student List for Course ——PAT甲级真题

    1047 Student List for Course Zhejiang University has 40,000 students and provides 2,500 courses. Now ...

  5. 1047. Student List for Course (25)

    Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li ...

  6. PAT 甲级 1047 Student List for Course

    https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960 Zhejiang University ha ...

  7. PAT 1047. Student List for Course

    Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li ...

  8. 1047 Student List for Course (25分)

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

  9. PAT (Advanced Level) 1047. Student List for Course (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. jQuery---jquery.color.js和jquery.lazyload.js的使用

    jquery.color.js的使用 了解即可 <!--1. 引入jquery的js文件--> <script src="jquery-1.12.4.js"> ...

  2. jQuery---钢琴案例 (按下1-9数字键,能触发对应的mouseenter事件)

    钢琴案例 (按下1-9数字键,能触发对应的mouseenter事件) 1. 结合之前的学习,主要内容,就是on注册keyup事件,函数里传入e, 用e.keyCode,来获取1-9的数字的范围. 如果 ...

  3. .net 父类值赋给子类

    1.最简单的方式,反射+泛型 优点:字段修改时,无需更改代码,只需要更新实体即可 缺点:因为用到反射,可能效率会稍微弱那么一点点,没有实际用太多字段测试 public static cClass Pa ...

  4. Java 【instanceof使用】

    一.instanceof使用 public class demo{ public static void main(String[] args){ String name = “hello”; boo ...

  5. 通过 Chrome浏览器 查看http请求报文

    as we all know  HTTP 请求报文 包含请求行.请求头和请求体三部分 请求行:(请求方式 资源路径 协议/版本) 例如:POST /test/index.html HTTP/1.1 P ...

  6. Linux第一周作业

    1.按系列罗列linux的发行版,并描述不同发行版之间的联系与区别. Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户,多任务,支持多线程和多CPU的操作 ...

  7. python下timer定时器常用的两种实现方法

    方法一,使用线程中现成的:   这种一般比较常用,特别是在线程中的使用方法,下面是一个例子能够很清楚的说明它的具体使用方法: #! /usr/bin/python3 #! -*- conding: u ...

  8. ZooKeeper启动报错:My id 3 not in the peer list

    错误描述: 解决方法:查看zookeeper-3.4.2/conf目录下 编辑zoo.cfg文件 发现第三行有问题修改

  9. VMware、Linux(CentOS 7)安装,供参考。

    前端开发,学习Linux,记录安装中的一些问题,比如在安装最小版后,如何由命令行转为图形界面等. -------------笔记中截图参考其他资料. 下载文件 VMware 12: 链接:https: ...

  10. Spark学习之路 (二十三)SparkStreaming的官方文档[转]

    SparkCore.SparkSQL和SparkStreaming的类似之处 SparkStreaming的运行流程 1.我们在集群中的其中一台机器上提交我们的Application Jar,然后就会 ...