【PAT甲级】1039 Course List for Student (25 分)(vector嵌套于map,段错误原因未知)
题意:
输入两个正整数N和K(N<=40000,K<=2500),分别为学生和课程的数量。接下来输入K门课的信息,先输入每门课的ID再输入有多少学生选了这门课,接下来输入学生们的ID。最后N次询问,输入学生的ID输出该学生选了多少们课,输出所选课程的数量,按照递增序输出课程的ID。
trick:
第5个数据点出现段错误,把原本以map存学生对应ID再映射vector存储该学生所选课程改成vector嵌套在map内,就没有段错误的问题出现,疑似映射过程中指针漂移???
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,vector<int> >name;
string s;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k;
cin>>n>>k;
int x,num;
int cnt=;
for(int i=;i<=k;++i){
cin>>x>>num;
for(int j=;j<=num;++j){
cin>>s;
if(name.find(s)==name.end())
name[s]=vector<int>{x};
else
name[s].push_back(x);
}
}
string ss;
for(int i=;i<=n;++i){
cin>>ss;
auto&idd=name[ss];
cout<<ss<<" "<<idd.size();
sort(idd.begin(),idd.end());
for(auto it:idd)
cout<<" "<<it;
cout<<"\n";
}
return ;
}
【PAT甲级】1039 Course List for Student (25 分)(vector嵌套于map,段错误原因未知)的更多相关文章
- PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*
1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 cours ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT甲级:1089 Insert or Merge (25分)
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...
- PAT 甲级 1145 Hashing - Average Search Time (25 分)(读不懂题,也没听说过平方探测法解决哈希冲突。。。感觉题目也有点问题)
1145 Hashing - Average Search Time (25 分) The task of this problem is simple: insert a sequence of ...
- PAT 甲级 1066 Root of AVL Tree (25 分)(快速掌握平衡二叉树的旋转,内含代码和注解)***
1066 Root of AVL Tree (25 分) An AVL tree is a self-balancing binary search tree. In an AVL tree, t ...
- PAT 甲级 1055 The World's Richest (25 分)(简单题,要用printf和scanf,否则超时,string 的输入输出要注意)
1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires base ...
- PAT 1039 Course List for Student (25分) 使用map<string, vector<int>>
题目 Zhejiang University has 40000 students and provides 2500 courses. Now given the student name list ...
- 【PAT甲级】1110 Complete Binary Tree (25分)
题意: 输入一个正整数N(<=20),代表结点个数(0~N-1),接着输入N行每行包括每个结点的左右子结点,'-'表示无该子结点,输出是否是一颗完全二叉树,是的话输出最后一个子结点否则输出根节点 ...
- 【PAT甲级】1062 Talent and Virtue (25 分)
题意: 输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线.接着输入N行数据,每行包括一个人的ID,道德数值和才能数值.一 ...
随机推荐
- 百炼OJ - 1003 - Hangover
题目链接 思路 求一个数列的前n项和(1/2, 1/3, ...., 1/n)大于所给数所需的项数. #include<stdio.h> int main() { float a; whi ...
- mongo的常用命令--转载
转载liyonghui的博文,出处 http://www.cnblogs.com/liyonghui/p/mongodb.html 博主写的特别好,对于我这个新手帮了大忙了,还将mongo和mysq ...
- Codeforces Round #598 (Div. 3) C. Platforms Jumping
There is a river of width nn. The left bank of the river is cell 00 and the right bank is cell n+1n+ ...
- Java进阶学习(4)之继承与多态.demo
多媒体数据库小练习 package com.dome; import java.util.ArrayList; public class Database { // private ArrayList ...
- 左偏树(p4431)
难得不是左偏树,而是思维: 这道题在做得时候,有两个性质 1.如果a是一个不下降序列,那么b[i]==a[i]时取得最优解. 2.如果a是一个严格递减序列,则取a序列的中位数x,令b[1]=b[2]= ...
- 微信个人支付接口---YunGouOS 1.1.3 版本发布,新增个人微信/支付宝收款接口
软件接口 https://www.oschina.net/news/113305/yungouos-1-1-3-released 文档说明 https://www.oschina.net/p/Yu ...
- RedHat7 / CentOS 7 忘记root密码修改
摘自:https://blog.csdn.net/bubbleyang/article/details/91360856 进入互动式命令环境 开机出现 grub boot loader 开机选项菜单时 ...
- VMware安装EVE
众所周知,EVE是一个非常强大的仿真环境,能给我们学习带来很大的帮助,这里主要简单记录一下安装在VMware下安装EVE的过程. 1.准备: 我安装的VMware是WORKSTATION 12 PRO ...
- github是什么,有什么用
转载连接:https://blog.csdn.net/obkoro1/article/details/68066441 写在前面:关于github的文章我已经写了两篇了,关于github个人网站搭建和 ...
- 【PAT甲级】1089 Insert or Merge (25 分)(插入排序和归并排序)
题意: 输入一个正整数N(<=100),接着输入两行N个整数,第一行表示初始序列,第二行表示经过一定程度的排序后的序列.输出这个序列是由插入排序或者归并排序得到的,并且下一行输出经过再一次排序操 ...