【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,道德数值和才能数值.一 ...
随机推荐
- redis持久化优缺点
- JS-ES6语法运用
import导入模块,js的模块化开发 浏览器使用ES6模块化语法(使用module时js代码自动运行严格模式): <script type="module" src=&qu ...
- 剑指offer 面试题35.复杂链表的复制
时间O(N),空间O(N) /* struct RandomListNode { int label; struct RandomListNode *next, *random; RandomList ...
- MyBatis(2)——增删改查
增删改查: 1.在实体类的映射文件中增加insert.update.delete标签与数据库语句,例如 <!-- 会去获取到对应的实体类的getter方法 --> <insert i ...
- python测量代码运行时间方法
Python 社区有句俗语: “python自己带着电池” ,别自己写计时框架. Python3.2具备一个叫做 timeit 的完美计时工具可以测量python代码的运行时间. timeit 模块: ...
- 第二十五篇 玩转数据结构——链表(Linked List)
1.. 链表的重要性 我们之前实现的动态数组.栈.队列,底层都是依托静态数组,靠resize来解决固定容量的问题,而"链表"则是一种真正的动态数据结构,不需要处理固定容 ...
- Linux - 命令 - 查找命令总结
关于查找文件的几个命令 一.find命令 find是最常用也是最强大的查找命令,可以查找任何类型的文件 find命令的一般格式: find <指定目录><指定条件><指定 ...
- tomcat在win10系统中安装失败的问题,修改tomcat内存
自己以前在其他系统上安装tomcat服务都没有问题,但是在win10系统上安装就经常出现问题,自己总结了一下安装步骤: 1.首先需要配置环境变量, CATALINA_HOME 2.修改service. ...
- 2.1 【配置环境】 JDK + eclipse + selenium
1.jdk以及eclipse的具体安装详见 http://www.cnblogs.com/ericazy/p/6082194.html 安装1.7 jdk即可 2.selenium 旧版本安装: s ...
- markdown pic
Markdown 图片 Markdown 图片语法格式如下:   开头一个感叹号 ! 接着一个方括 ...