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 (≤104) 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<bits/stdc++.h>
using namespace std; struct Book{
string bookId;
string title;
string author;
set<string> keywords;
string publisher;
string year;
}; map<string,set<string> > Title,Author,Publisher,Keyword,Year; set<string> change(string str){
int len=(int)str.size();
set<string> ans;
string word=""; for(int i=;i<len;i++){
char c=str[i];
if(c!=' '){
word+=c;
}else{
ans.insert(word);
word.clear();
}
}
ans.insert(word); return ans;
} void GetQuery(map<string,set<string> >&mp,string &query){//传参慢用引用
if(mp.find(query)==mp.end()){
cout<<"Not Found\n";
}else{
for(set<string>::iterator it=mp[query].begin();it!=mp[query].end();it++)
{
cout<<*it<<"\n";
}
} } int main(){ ios::sync_with_stdio(false);
cin.tie(); int n;
cin>>n; cin.get(); string str; for(int i=;i<n;i++){
Book book; getline(cin,book.bookId);
getline(cin,book.title);
getline(cin,book.author); getline(cin,str);
book.keywords=change(str); getline(cin,book.publisher);
getline(cin,book.year); Title[book.title].insert(book.bookId);
Author[book.author].insert(book.bookId);
Publisher[book.publisher].insert(book.bookId);
Year[book.year].insert(book.bookId); for(set<string>::iterator it=book.keywords.begin();it!=book.keywords.end();it++){
Keyword[*it].insert(book.bookId);
} } int m; cin>>m; string query,origin; cin.get(); for(int i=;i<m;i++ ){
getline(cin,query);
origin=query; int type=query[]-''; query=query.erase(,); cout<<origin<<"\n"; switch(type){
case : GetQuery(Title,query);break;
case : GetQuery(Author,query);break;
case : GetQuery(Keyword,query);break;
case : GetQuery(Publisher,query);break;
case : GetQuery(Year,query);break;
}; } return ;
}
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 ...
- PAT Advanced 1022 Digital Library (30 分)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 【PAT甲级】1022 Digital Library (30 分)(模拟)
题意: 输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份. 然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没 ...
- pat 甲级 1022. Digital Library (30)
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...
- 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 ...
- 1022 Digital Library (30)(30 point(s))
problem A Digital Library contains millions of books, stored according to their titles, authors, key ...
- PAT-1022 Digital Library (30 分) 字符串处理
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
随机推荐
- 解决:The “https://packagist.laravel-china.org/packages.json” file could not be downloaded
使用composer安装错误提示: The "https://packagist.laravel-china.org/packages.json" file could not b ...
- 8. Jmeter导入jar包
我们都知道Jmeter是Java编写的,所以有很多时候需要用到Java方面的知识.比如Jmeter前置处理器,就用到了很多Java知识.那么本章我们先介绍如何使用Jmeter导人jar包. 工具准备 ...
- Java构造函数(构造器)
构造函数是用于在对象创建后立即初始化对象的代码块.构造函数的结构看起来类似于一个方法. 声明构造函数 构造函数声明的一般语法是: 1 2 3 <Modifiers> <Constru ...
- 分布式ID生成器的解决方案总结
在互联网的业务系统中,涉及到各种各样的ID,如在支付系统中就会有支付ID.退款ID等.那一般生成ID都有哪些解决方案呢?特别是在复杂的分布式系统业务场景中,我们应该采用哪种适合自己的解决方案是十分重要 ...
- Python 如何debug
一.常见错误: 1.漏了末尾的冒号,如 if语句,循环语句,定义函数 2.缩进错误,该缩进的时候没有缩进 3.把英文符号写成中文符号,如: ' ' () , 4.字符串拼接,把字符串和数字拼接一起 ...
- uoj175 【Goodbye Yiwei】新年的网警
题目 胡乱分析 不妨定谣言的源头得到谣言的时刻为\(1\),那么其他人听到谣言的时间就是源头到这个点的最短路 假设\(i\)是谣言的源头,那么如果存在一个点\(j\)满足\(\forall k\in[ ...
- csdn加入暂时会话功能
版权声明:本文为博主原创文章.若要转载请注明出处! ^_^ https://blog.csdn.net/u010892841/article/details/25334153 ...
- spring security 学习三-rememberMe
功能:登录时的“记住我”功能 原理: rememberMeAuthenticationFilter在security过滤器链中的位置,在请求走认证流程是,当前边的filter都不通过时,会走remem ...
- ArcMap属性表操作接口ITableWindow3
ITableWindow3 tableWindow3 = new TableWindowClass { //Layer = laye ...
- 【目录】mysql 进阶篇系列
随笔分类 - mysql 进阶篇系列 mysql 开发进阶篇系列 55 权限与安全(安全事项 ) 摘要: 一. 操作系统层面安全 对于数据库来说,安全很重要,本章将从操作系统和数据库两个层面对mysq ...