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. SpringBoot图文教程6—SpringBoot中过滤器的使用

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文系列教程技术大纲 鹿老师的Java笔记 SpringBo ...

  2. 【读书笔记】自然语言处理综述 -- 第四章 -- N元语法

    第四章 N元语法 本章开篇的两句话很有意思,代表了当时两个学派的思想和矛盾. 一句是"有史以来最伟大的语言学家"乔姆斯基说的:"句子的概率,在任何已知的对于这个术语的解释 ...

  3. jrtp 使用

    jrtplib-3.11.1 使用jthread-1.3.3 # cmake 下载https://cmake.org/download/ 使用地址https://github.com/j0r1/JRT ...

  4. D - Counting Squares

    Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) t ...

  5. sublime修改快捷键样式

    样式----------------{ "always_show_minimap_viewport": true, "auto_find_in_selection&quo ...

  6. 2020省选模拟训练1 排列(perm)多项式exp+EGF

    这道题真的还是简单的一批..... 我当时要是参加考试的话该多好(凭这一道题就能进前 5 了) 十分显然的指数型生成函数. 令 $f[i]$ 表示有 $i$ 个点的答案. 然后显然有 $f[i]=\s ...

  7. mybatis第二天02

    MyBatis第二天内容 1.mybatis的执行原理 通过: 1.全局配置文件SqlMapConfig.xml  映射文件mapper.xml 获取得到SqlSessinFactory工厂 2.由工 ...

  8. 安装Docker到Ubuntu(APT)

    运行环境 系统版本:Ubuntu 16.04.5 LTS 软件版本:Docker-CE-18.09.5 硬件配置:无 安装过程 1.卸载旧版本 root@ubuntu:~# sudo apt-get ...

  9. HDFS的扩容

    一.扩容 1.1横向扩容:加节点    https://www.cnblogs.com/the-roc/p/12362926.html 1.2纵向扩容:加硬盘 二.纵向扩容 2.1添加硬盘 2.2在关 ...

  10. js面向对象怎么理解

    js面向对象怎么理解 <一>. 认识对象.首先要认识对象:在编程中,对象(object)是具体的某一个实例,唯一的某一个个体.如:电脑就是一个统称,而你面前的这一台电脑就是对象.而电脑的统 ...