https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336


解析: 将每一部分都用哈希表映射。映射的结果是一个集合set, set可以自动排序,减少了我们排序的步骤。
需要注意的是第三点关键字查询,我们的一本书有很多的关键字,故所有的关键字都要拆分映射。


#include<bits/stdc++.h>
using namespace std;
unordered_map<string,set<string>> hush[6];
int n,m;
string id,s[6];
int main(void)
{cin>>n;getline(cin,id);for(int i=0;i<n;i++){getline(cin,id);for(int j=1;j<=5;j++) getline(cin,s[j]);for(int j=1;j<=5;j++){if(j!=3) hush[j][s[j]].insert(id);else //是第三点{stringstream l(s[j]);string temp;while(l>>temp) hush[j][temp].insert(id);//拆分关键字分别映射}}}cin>>m; string temp; getline(cin,temp);for(int i=0;i<m;i++){getline(cin,temp);cout<<temp<<endl;int op=temp[0]-'0';temp=temp.substr(3);auto t=hush[op][temp];if(t.size()) {for(auto i=t.begin();i!=t.end();i++) cout<<*i<<endl;}else cout<<"Not Found"<<endl;}return 0;
}

1022 Digital Library (30 分) 【难度: 中 / 知识点: 哈希表】相关推荐

  1. PAT甲级1022 Digital Library (30分):[C++题解]结构体、排序、查询

    文章目录 题目分析 题目链接 题目分析 分析: 一本书信息由6个,想到用结构体来存. 至于每一个信息可以用string来存,而关键字在想使用vector<string> keywords还 ...

  2. 1020 Tree Traversals (25 分) 【难度: 中 / 知识点: 哈希表建树 遍历树】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805485033603072 第一步: 建树 第二步: 遍历树 #incl ...

  3. 1022. Digital Library (30) -map -字符串处理

    题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...

  4. 1022. Digital Library (30)

    考察倒排索引 #include<iostream> #include<string> #include<vector> #include<algorithm& ...

  5. 1078 Hashing (25 分)【难度: 一般 / 知识点: 哈希表二次探测法】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805389634158592 不得不说,读了半天的假题,以为就是直接判断可 ...

  6. 1071 Speech Patterns (25 分)【难度: 简单 / 知识点: 哈希表 字符串】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805398257647616 将不合法的字符都弄成空格符,然后用strin ...

  7. 1022. Digital Library

    字符串处理能力有待提高 // 1022. Digital Library.cpp: 主项目文件.#include "stdafx.h" #include <cstdio> ...

  8. c ++中哈希表如何访问_C / C ++中的哈希表–完整的实现

    c ++中哈希表如何访问 A Hash Table in C/C++ (Associative array) is a data structure that maps keys to values. ...

  9. 哈希表 matlab实现,MATLAB中的哈希表

    MATLAB中的哈希表 MATLAB是否支持散列表? 一些背景 我正在研究Matlab中的一个问题,需要图像的尺度空间表示. 为了做到这一点,我创build了一个二维高斯滤波器,在一定范围内为方差si ...

最新文章

  1. 5000万用户数据泄露,大数据时代隐私保护困难重重
  2. java基本语法借阅_课内资源 - 基于Java和MySql实现的光盘借阅管理系统
  3. 微信小程序支付返回信息为空
  4. 【算法】—— 不借助中间变量实现 swap
  5. Java字符串replaceAll()方法
  6. 谈谈自己对投影、SVD和傅里叶变换的理解
  7. mapreduce 的partitioner,GroupComparator,KeyComparator,分布式缓存使用示例
  8. eclipse svn回滚之前版本
  9. 3串锂电池充电保护板设计
  10. python实现蒙特卡洛模拟_蒙特卡洛模拟(Python)深入教程
  11. After Effects CC 2019 中文版软件下载 /破解教程
  12. P2433 【深基1-2】小学数学 N 合一
  13. 提问的艺术,原文链接
  14. QQ守卫农场辅助--QQ守卫农场外挂
  15. 【软件测试】——软件测试经验总结
  16. Halcon 回形针方向计算
  17. MarkDown语法详解
  18. 深度学习(6)之卷积的几种方式:1D、2D和3D卷积的不同卷积原理(全网最全!)
  19. 【考研复试】计算机相关专业面试英语自我介绍范文(一)
  20. 云服务器nginx站点主页路径更改方法

热门文章

  1. PHP5.6通过CURL上传图片@符无效的兼容问题
  2. Interval query
  3. windows系统中hosts文件位置
  4. ionic 完美仿微信摇一摇
  5. [读书笔记]C#学习笔记三: C#类型详解..
  6. 一款超炫的图片排列特效
  7. linux shell if 或和且的表示方法
  8. 找不到QtDir变量的解决办法, 同时不需要经过编译就可以使用qt 库
  9. 拔掉网线时Socket的检查方法
  10. C语言中函数可变参数解析