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. 41.Python中加载静态文件

    在一个网页中,不仅仅只有一个html骨架,还需要css样式文件,js执行文件以及一些图片等.因此在DTL中加载静态文件时一个必须要解决的问题.在DTL中,使用static标签来加载静态文件.要使用st ...

  2. PP: Unsupervised anomaly detection via variational auto-encoder for seasonal KPIs in web applications

    Problem: unsupervised anomaly detection for seasonal KPIs in web applications. Donut: an unsupervise ...

  3. Pikachu-SSRF(服务器端请求伪造)

    SSRF(Server-Side Request Forgery:服务器端请求伪造) 其形成的原因大都是由于服务端提供了从其他服务器应用获取数据的功能,但又没有对目标地址做严格过滤与限制 导致攻击者可 ...

  4. gitkraken生成ssh keys并连接git

    gitkraken中生成ssh keys 打开gitkraken ,点击左上file,选择preferences 需要选择一个指定目录 将复制的ssh keys粘贴到gitlab 或者 GitHub中 ...

  5. redis中获取每个数据类型top-n的bigkeys信息

    需求:之前写的脚本获取redis 最大的top-n的bigkeys,没有区分数据类型,如果要针对每个数据类型的前top-n的bigkeys获取呢? db_ip=5.5.5.101 db_port= p ...

  6. ubuntu下opencv CMakeLists.txt编写

    # 声明要求的 cmake 最低版本 cmake_minimum_required( VERSION 2.8 ) # 声明一个 cmake 工程 project( pro ) # 设置编译模式 set ...

  7. jQuery Moblie 问题汇总

    1  使用jQuery动态添加html,没有jQuery Moblie的样式 $("body").html(listview);//以上代码只是把结构加上去了,但是却没有加上jqm ...

  8. python之路(集合,深浅copy,基础数据补充)

    一.集合:类似列表,元组的存储数据容器,不同点是不可修改,不可重复.无序排列. 1.创建集合: (1).set1 = {'abby', 'eric'} result:{'eric', 'abby'} ...

  9. Linux 一些使用工具

    ssh 链接使用工具xshell 下载链接 http://www.onlinedown.net/soft/36383.htm 映射硬盘工具 sftpdriver 安装输入服务器之后链接 并且输入注册码 ...

  10. 野路子码农系列(8)我终于大致搞懂了GBDT

    由于下下周要在组里介绍一个算法,最近开始提前准备,当初非常自信地写下自己最喜欢的GBDT,但随着逐步深入,发现其实自己对这个算法的细节并不是非常了解,了解的只是一些面试题的答案而已……(既然没有深入了 ...