1047 Student List for Course
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的更多相关文章
- PAT 解题报告 1047. Student List for Course (25)
1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...
- PAT 1047 Student List for Course[一般]
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cours ...
- 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 ...
- 1047 Student List for Course ——PAT甲级真题
1047 Student List for Course Zhejiang University has 40,000 students and provides 2,500 courses. Now ...
- 1047. Student List for Course (25)
Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li ...
- PAT 甲级 1047 Student List for Course
https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960 Zhejiang University ha ...
- PAT 1047. Student List for Course
Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li ...
- 1047 Student List for Course (25分)
Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course ...
- PAT (Advanced Level) 1047. Student List for Course (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- PRML学习准备
因为很怕PRML课程,所以想提前学习下做点准备. 看的一个学习内容就是python数据处理那本书,比较仔细地学习了 numpy,大致看了pandas和 matplotlib ,有以下几点感受 nump ...
- Enityt模型特性
数据验证相关的数据注解: 特性 解释 Remote 使用 jQuery 验证插件远程验证程序的特性 FileExtension 验证文件扩展名 Compare 比较两个属性的值 RegularExpr ...
- Windows通过DOS命令行设置IP地址
@rem 设置固定IP地址netsh interface ip set address "本地连接" static 192.168.1.200 255.255.255.0 192. ...
- Ubuntu 搭建phpcms
安装Apache2 $ sudo apt-get update -y $ sudo apt-get install apache2 -y $ sudo systemctl start apache2. ...
- React网络请求跨域代理设置
之前的之所以可以请求其他域名下的网络数据,是因为我们在服务端设置了相关配置,如下所示 如果将其注释掉,再次测试,如下所示 此时便无法跨域操作,接下来介绍下React如何实现跨域代理 (1)分析 Rea ...
- 解决kbmMW Scheduler在任务中停止任务遇到的问题
procedure TCustomGridViewCameraDoc.InitSchedule; begin Scheduler.Schedule( procedure(const ASchedule ...
- Postman使用技巧
Postman是什么 Postman是chrome的一款插件,用于做接口请求测试,无论是前端,后台还是测试人员,都可以用postman来测试接口,用起来非常方便. Postman安装 官网下载(翻墙) ...
- ZooKeeper启动报错:My id 3 not in the peer list
错误描述: 解决方法:查看zookeeper-3.4.2/conf目录下 编辑zoo.cfg文件 发现第三行有问题修改
- Android 存档最优选项
1 开发环境:VS2019最新版本(16.4.5) 2 存档最优选项 说明:apk包70M(默认选项),apk包12M(调整后选项) 位置:Android 选项
- ECMAScript基本语法——⑤运算符 比较运算符
><>=<======全等于 比较运算符 Java中只能比类型相同的,JavaScript没有限制比较方式 1.类型相同:直接比较 字符串:安装字典顺序比较.按位逐一比较直到比 ...