A1022. Digital Library
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 (<=10000) 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 (<=1000) 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
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<set>
using namespace std;
map<string, set<int>> mp1, mp2, mp3, mp4, mp5;
void show(map<string, set<int>> &mp, string &key){
set<int> ::iterator it;
int find = ;
for(it = mp[key].begin(); it != mp[key].end(); it++){
printf("%07d\n", *it);
find = ;
}
if(find == )
printf("Not Found\n");
}
int main(){
int N, M, id;
string ss, ss2;
scanf("%d ", &N);
for(int i = ; i < N; i++){
scanf("%d ", &id);
getline(cin, ss);
mp1[ss].insert(id);
getline(cin, ss);
mp2[ss].insert(id);
while(cin >> ss){
char c = getchar();
mp3[ss].insert(id);
if(c == '\n')
break;
}
getline(cin, ss);
mp4[ss].insert(id);
getline(cin, ss);
mp5[ss].insert(id);
}
scanf("%d ", &M);
for(int i = ; i < M; i++){
getline(cin, ss2);
cout << ss2 + "\n";
ss = ss2.substr();
if(ss2[] == ''){
show(mp1, ss);
}else if(ss2[] == ''){
show(mp2, ss);
}else if(ss2[] == ''){
show(mp3, ss);
}else if(ss2[] == ''){
show(mp4, ss);
}else if(ss2[] == ''){
show(mp5, ss);
}
}
cin >> N;
return ;
}
总结:
1、题意:先输入书的id、名字、作者、关键词、出版社、出版时间。然后根据除书id以外的信息来查询书的id。注意其中书的关键词在输入时为一行字符串,其实是多个关键词以空格分开。由于一个信息可能对多本书(一个出版社有多本书...),且在查询结果时需要有序输出,所以可以使用 map<string , set<int>> 存储。
2、对于下面信息的第4行,需要分别读出每个单词,可以这么做
1111111
The Testing Book
Yue Chen
test code debug sort keywords
ZUCS Print
2011
while(cin >> ss){
char c = getchar();
mp3[ss].insert(id);
if(c == '\n')
break;
}
而当要用cin 读入带空格的一行时,可以 getline(cin , str);
3、在函数传参时,如果参数中有map、set、string等,应该传引用,否则可能会超时。
A1022. Digital Library的更多相关文章
- PAT甲级——A1022 Digital Library
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 【算法笔记】A1022 Digital Library
题意 输入n本书的信息:id,书名,作者,关键字,出版社,出版年份.搜索图书,输出id. 思路 定义5个map<string, set<int> >,分别存放Title, Au ...
- [PAT] A1022 Digital Library
[题目大意] 给出几本书的信息,包括编号,名字,出版社,作者,出版年份,关键字:然后给出几个请求,分别按照1->名字,2->出版社等对应信息查询符合要求的书的编号. [思路] 模拟. [坑 ...
- 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 ...
- PAT1022.:Digital Library
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...
- PAT 甲级 1022 Digital Library
https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...
- PAT 1022 Digital Library[map使用]
1022 Digital Library (30)(30 分) A Digital Library contains millions of books, stored according to th ...
- 1022 Digital Library (30)(30 point(s))
problem A Digital Library contains millions of books, stored according to their titles, authors, key ...
随机推荐
- MySQL主主同步配置
1. MySQL主主配置过程 在上一篇实现了主从同步的基础上,进行主主同步的配置. 这里用node19(主),node20(从)做修改,使得node19和node20变为主主同步配置模式 修改配置文件 ...
- width,height为多少px时,A4纸打印时刚好一页?
计算方式一般的分辨率为XX像素/英寸,其中一英寸为25.4毫米.所以一毫米的像素数就为XX/25.4.现在的工作就是求XX的值了,把XX的值求出来以后,直接用XX/25.4 * 210就得到A4纸的像 ...
- 一文让你完全弄懂Stegosaurus
国内关于 Stegosaurus 的介绍少之又少,一般只是单纯的工具使用的讲解之类的,并且本人在学习过程中也是遇到了很多的问题,基于此种情况下写下此文,也是为我逝去的青春时光留个念想吧~ Stegos ...
- 系统、决策、控制研究系列(SSDC)
本类目主要介绍的书籍来自springer的系列书籍中的一本,对于该系列书籍介绍如下: “系统.决策及控制研究”(SSDC)系列涵盖了在广泛认知的系统.决策及控制的各个领域的快速.最新和高质量的最新发展 ...
- ZJOI2008 生日聚会Party
对于任意连续区间的限制,可以转化为以i结尾的所有区间的限制.这个转换在昨天的后缀自动机题也有用到,因此将其命名为区后变换.稍加分析后,我们记录以i结尾任意区间最大差即可进行DP转移.这个转换同时也创造 ...
- [2019BUAA软件工程]结对编程感想
结对编程感想 写在前面 本博客为笔者在完成软件工程结对编程任务后对于编程过程.最终得分的一些感想与经验分享.此外笔者还对于本课程的结对编程部分提出了一些建议. Tips Link 作业要求博客 2 ...
- Windows10安装ubuntu & caffe GPU版
1.Ubuntu https://www.cnblogs.com/EasonJim/p/7112413.html https://blog.csdn.net/jesse_mx/article/deta ...
- 使用代理创建连接池 proxyPool
配置文件properties url=jdbc:mysql://127.0.0.1:3306/mine?characterEncoding=UTF-8 user=root password=1234 ...
- 广商博客冲刺第四五天new
第三天沖刺傳送門 第六七天沖刺傳送門 以上的前台设计架构已经完成了,现在来完成前台的安卓设计. 首先我们配置了Android SDK Manager 使得程序能在安卓环境下运行. 这就完成了前台安卓的 ...
- ASP.NET MVC应用安全性(一)——自定义错误处理
很多 ASP.NET MVC 开发者都会写出高性能的代码,很好地交付软件,等等.但是却并没有安全性方面的计划. 有一种攻击是攻击者截获最终用户提交的表单数据,将其改变再将修改后的数据发送到服务器. ...