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 (≤10​4​​) 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 分)的更多相关文章

  1. PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)

    1022 Digital Library (30 分)   A Digital Library contains millions of books, stored according to thei ...

  2. PAT Advanced 1022 Digital Library (30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  3. 【PAT甲级】1022 Digital Library (30 分)(模拟)

    题意: 输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份. 然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没 ...

  4. pat 甲级 1022. Digital Library (30)

    1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...

  5. 1022 Digital Library (30)(30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  6. 1022. Digital Library (30)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

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

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

  8. 1022 Digital Library (30)(30 point(s))

    problem A Digital Library contains millions of books, stored according to their titles, authors, key ...

  9. PAT-1022 Digital Library (30 分) 字符串处理

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

随机推荐

  1. 三.通过jenkins对系统的监控(2)

    在这记录下,通过HTTP Request Plugin监控系统的异常.和上一篇原理差不多. 1.首先需要安装HTTP Request Plugin.插件安装好后,在系统设置下面会新增如下配置: 具体有 ...

  2. (9)C++ 对象和类

    一.类 1.访问控制 class student { int age;//默认私有控制 public: string name; double weight; }; 2.成员函数 定义成员函数时,使用 ...

  3. ubuntu 开机启动shell脚本

    1.创建shell启动脚本test 2.将启动脚本复制到 /etc/init.d 目录下 3.设置脚本文件权限 sudo chmod 755 /etc/init.d/test 4.设置脚本启动 sud ...

  4. CSS3 resize 属性

    CSS3 resize 属性 CSS 参考手册 实例 规定可以由用户调整 div 元素的大小: div { resize:both; overflow:auto; } 支持 Firefox 4+.Ch ...

  5. java入门经验分享——记面向对象先导课程学习感想

    选择在暑期学习面向对象先导课程的初衷是为大二下学期面向对象课程做一些铺垫,接触入门java语言.在接触java的过程中,就编程语言的学习方法而言,我从刚入学时的手慌脚乱四处寻求帮助到现在慢慢养成了自己 ...

  6. 在doker上的python安装及环境部署

    python环境部署 我们今天学习的内容是如何将Django项目部署到linux服务器上,我们部署的linux系统是centos7首先,我们先在linux上搭建我们的Python3环境: 在这里首先强 ...

  7. Linux下JDK1.6升级1.8版本

    先不管是否已安装JDK1.6还是JDK1.7,先下载 jdk-8u45-linux-x64.rpm 然后上传到  /usr/local/src  去.当然其他目录也可以.这里是默认位置   给所有用户 ...

  8. 软件开发程序猿日常必备,现用现查&日志记录

    日志记录-- logging模块 日志用处: 1.记录用户信息 2.记录个人流水 3.记录软件的运行状态 4.记录程序员发出的指令(跳板机) 5.用于程序员代码调试(print特别消耗内存,在开发测试 ...

  9. WPF非UI线程访问网络资源造成页面假死现象

    公司内部一个项目是用WPF作为GUI 访问web接口的形式获取数据, 但是由于数据量比较大,也没做分页,于是就需要一个loading的控件,网上查了很多资料但都比较浅.这里完成需求后,总结一下. 首先 ...

  10. Linux上的VirtualBox如何使用USB

    问题: VirtualBox设置中已经启用了"USB2.0(EHCI)控制器"选项,但是虚拟机中始终没有USB设备,右下角的状态也显示没有连接任何USB设备,看起来像是Virtua ...