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 ...
随机推荐
- Java 从入门到进阶之路(十七)
在之前的文章我们介绍了一下 Java 中类的内部类,本章我们来看一下 Java 中的正则表达式. 在任何一种语言中,都绕不开正则表达式,而且大部分语言的正则表达式都有预定义的字符集,且预定义的字符集也 ...
- 字符串模式匹配算法系列(三):Trie树及AC改进算法
Trie树的python实现(leetcode 208) #!/usr/bin/env python #-*- coding: utf-8 -*- import sys import pdb relo ...
- JOGL教程
本章介绍了OpenGL,Java OpenGL绑定(GL4java,LWJGL,JOGL)和JOGL比其他的OpenGL的优点. Java支持OpenGL(JOGL)是近期在Java OpenGL图形 ...
- 转 loadrunner11 录制 chrome 浏览器
chrome不设置代理的原始状态 图1 [LoadRunner]解决LR11无法录制Chrome浏览器脚本问题 LoadRunner录制脚本时,遇到高版本的IE.FireFox,或者Chrome浏 ...
- Python django tests
单元测试函数必须以test_开头,否则无法被识别
- Java开发最常犯的10个错误,打死都不要犯!
原文:http://www.programcreek.com/2014/05/top-10-mistakes-java-developers-make/ 译文:cnblogs.com/chenpi/p ...
- 分布式ID生成器的解决方案总结
在互联网的业务系统中,涉及到各种各样的ID,如在支付系统中就会有支付ID.退款ID等.那一般生成ID都有哪些解决方案呢?特别是在复杂的分布式系统业务场景中,我们应该采用哪种适合自己的解决方案是十分重要 ...
- Spark和pyspark的配置安装
如何安装Spark和Pyspark构建Spark学习环境[MacOs] JDK环境 Python环境 Spark引擎 下载地址:Apache-Spark官网 MacOs下一般安装在/usr/local ...
- java全栈商业小程序开发
此次开发只为学习和巩固,第一次学习开发 一.开发前需要了解: 开发框架MVVM.痛点.开源工具.VUE前端框架.微信支付模块.uni-app前端框架.小程序申请.开发工具下载.编写测试小程序.小程序结 ...
- android绑定usb前后摄像头
在Android的系统会有前置摄像头和后置摄像头的定义,摄像头分为SOC类型的摄像头和USB这一类的摄像头,接下要分析就是USB摄像头这一类 . 一般在android或者linux系统中分析一个模块, ...