PAT Advanced 1022 Digital Library (30 分)
A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number as its ID. Given any query from a reader, you are supposed to output the resulting books, sorted in increasing order of their ID's.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer N (≤) which is the total number of books. Then N blocks follow, each contains the information of a book in 6 lines:
- Line #1: the 7-digit ID number;
- Line #2: the book title -- a string of no more than 80 characters;
- Line #3: the author -- a string of no more than 80 characters;
- Line #4: the key words -- each word is a string of no more than 10 characters without any white space, and the keywords are separated by exactly one space;
- Line #5: the publisher -- a string of no more than 80 characters;
- Line #6: the published year -- a 4-digit number which is in the range [1000, 3000].
It is assumed that each book belongs to one author only, and contains no more than 5 key words; there are no more than 1000 distinct key words in total; and there are no more than 1000 distinct publishers.
After the book information, there is a line containing a positive integer M (≤) which is the number of user's search queries. Then M lines follow, each in one of the formats shown below:
- 1: a book title
- 2: name of an author
- 3: a key word
- 4: name of a publisher
- 5: a 4-digit number representing the year
Output Specification:
For each query, first print the original query in a line, then output the resulting book ID's in increasing order, each occupying a line. If no book is found, print Not Found instead.
Sample Input:
3
1111111
The Testing Book
Yue Chen
test code debug sort keywords
ZUCS Print
2011
3333333
Another Testing Book
Yue Chen
test code sort keywords
ZUCS Print2
2012
2222222
The Testing Book
CYLL
keywords debug book
ZUCS Print2
2011
6
1: The Testing Book
2: Yue Chen
3: keywords
4: ZUCS Print
5: 2011
3: blablabla
Sample Output:
1: The Testing Book
1111111
2222222
2: Yue Chen
1111111
3333333
3: keywords
1111111
2222222
3333333
4: ZUCS Print
1111111
5: 2011
1111111
2222222
3: blablabla
Not Found
我们使用一个unordered_map存储即可,unordered_map底层是哈希存储,我们在这题注意2点。
1.Not Found不要忘记
2.unordered_map存储的vector要进行一次排序
#include <iostream>
#include <vector>
#include <sstream>
#include <unordered_map>
#include <algorithm> using namespace std; bool cmp(string str1,string str2){
return str1<str2;
}
int main()
{
string id,key,tmp1,tmp2;
unordered_map<string,vector<string>> m;
//input
int N;cin>>N;getline(cin,tmp1);
for(int i=;i<N;i++){
getline(cin,id);
getline(cin,key);//book title
m[key].push_back(id);
getline(cin,key);//author
m[key].push_back(id);
getline(cin,tmp1);//kw
stringstream ss;
ss<<tmp1;
while(ss>>key) m[key].push_back(id);
getline(cin,key);//pbs
m[key].push_back(id);
getline(cin,key);//pbs_y
m[key].push_back(id);
}
int M;cin>>M;getline(cin,tmp1);
while(M--){//out
getline(cin,tmp1);
cout<<tmp1<<endl;
tmp1=tmp1.substr(,tmp1.length()-);
sort(m[tmp1].begin(),m[tmp1].end(),cmp);
if(m[tmp1].size()!=)
for(int i=;i<m[tmp1].size();i++) cout<<m[tmp1][i]<<endl;
else cout<<"Not Found"<<endl;
}
system("pause");
return ;
}
A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number as its ID. Given any query from a reader, you are supposed to output the resulting books, sorted in increasing order of their ID's.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer N (≤) which is the total number of books. Then N blocks follow, each contains the information of a book in 6 lines:
- Line #1: the 7-digit ID number;
- Line #2: the book title -- a string of no more than 80 characters;
- Line #3: the author -- a string of no more than 80 characters;
- Line #4: the key words -- each word is a string of no more than 10 characters without any white space, and the keywords are separated by exactly one space;
- Line #5: the publisher -- a string of no more than 80 characters;
- Line #6: the published year -- a 4-digit number which is in the range [1000, 3000].
It is assumed that each book belongs to one author only, and contains no more than 5 key words; there are no more than 1000 distinct key words in total; and there are no more than 1000 distinct publishers.
After the book information, there is a line containing a positive integer M (≤) which is the number of user's search queries. Then M lines follow, each in one of the formats shown below:
- 1: a book title
- 2: name of an author
- 3: a key word
- 4: name of a publisher
- 5: a 4-digit number representing the year
Output Specification:
For each query, first print the original query in a line, then output the resulting book ID's in increasing order, each occupying a line. If no book is found, print Not Found instead.
Sample Input:
3
1111111
The Testing Book
Yue Chen
test code debug sort keywords
ZUCS Print
2011
3333333
Another Testing Book
Yue Chen
test code sort keywords
ZUCS Print2
2012
2222222
The Testing Book
CYLL
keywords debug book
ZUCS Print2
2011
6
1: The Testing Book
2: Yue Chen
3: keywords
4: ZUCS Print
5: 2011
3: blablabla
Sample Output:
1: The Testing Book
1111111
2222222
2: Yue Chen
1111111
3333333
3: keywords
1111111
2222222
3333333
4: ZUCS Print
1111111
5: 2011
1111111
2222222
3: blablabla
Not Found
PAT Advanced 1022 Digital Library (30 分)的更多相关文章
- PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- 1022 Digital Library (30 分)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- pat 甲级 1022. Digital Library (30)
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...
- 【PAT甲级】1022 Digital Library (30 分)(模拟)
题意: 输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份. 然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没 ...
- PAT A 1022. Digital Library (30)【结构体排序检索】
https://www.patest.cn/contests/pat-a-practise/1022 直接模拟, 输入,按id排序,检索 #include <iostream> #incl ...
- 1022 Digital Library (30)(30 分)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 1022. Digital Library (30)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 1022. Digital Library (30) -map -字符串处理
题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...
- PAT 甲级 1022 Digital Library
https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...
随机推荐
- charles 偏好设置
本文参考:charles 偏好设置 charles 偏好设置 偏好设置,注意作用如下 用户界面 视图 启动设置 警告设置 视图选项 头和主体一起查看 请求和响应页查看 结构试图布局 序列试图布局 显 ...
- 配置Linux描述网络安全CIA模型之可用性案例
在Linux中防御SYN型DOS攻击的方法比较常见的有: 1.增大队列SYN最大半链接数 2.利用SYN cookie技术 下面分别进行分析. 1.增大队列SYN最大半连接数 在LINUX中执行命 ...
- python break/continue - python基础入门(10)
在昨天的文章:python while循环 文章结尾,我们留下了一个bug,当条件成立时,程序陷入了死循环,如何解决呢? 为了规避这个问题,今天介绍两个关键词:break和continue. ...
- mysql 按照配置文件启动
有时,我们的机器上面装了很多个mysql,但只有一个3306端口,其余的mysql服务器需要重新指定端口.我们需要多个配置文件来启动它们.那么我们怎么通过指定配置文件的方式来启动呢? 例如,按 ...
- 封装一个Model或者Vender类
Model <?php /** * User: Eden * Date: 2019/3/21 * 共有内容 */ class WxPayModel extends Model { protect ...
- Redis 集群_主从复制_哨兵模型
1 redis集群简介 1.1 集群的概念 所谓的集群,就是通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定.高效的状态. 1.1.1 使用redis集群的必要性 问题:我们已经部署好了 ...
- 【LOJ】#2137. 「ZJOI2015」诸神眷顾的幻想乡
我居然到了国赛之前才学习怎么做广义后缀自动机 这个题目--意思是--有20个叶子,肯定一条路径都是任意一个叶子为根,一个从某个点往祖先走的路径 这样的话我们可以按照dfs序,从每个节点的父亲那里的后缀 ...
- Python 同级目录import报错
在使用protobuf时,我们自己了各种Options的时候,在生成的python文件会在同级目录中引用,所以这个时候我们不能做到,加个__init__.py文件了事然后在文件里面写 import m ...
- C# EntityCollection 和 List 互转
private EntityCollection<T> ToEntityCollection<T>(this List<T> list) where T : cla ...
- Python练习_数据类型_day4
题目 1.作业 1,写代码,有如下列表,按照要求实现每一个功能 li = ["alex", "WuSir", "ritian", " ...