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. python 比较俩个列表中的元素是否相同

    如果元素都是数字: # a = [121, 144, 19, 161, 19, 144, 19, 11]# b = [121, 14641, 20736, 361, 25921, 361, 20736 ...

  2. Nginx网络架构实战学习笔记(六):服务器集群搭建、集群性能测试

    文章目录 服务器集群搭建 Nginx---->php-fpm之间的优化 302机器 202机器 压力测试 搭建memcached.mysql(数据准备) 今晚就动手-.- 集群性能测试 服务器集 ...

  3. C/S and B/S

    C/S结构,即Client/Server(客户机/服务器)结构,是大家熟知的软件系统体系结构,通过将任务合理分配到Client端和Server端,降低了系统的通讯开销,可以充分利用两端硬件环境的优势. ...

  4. springMvc注册时图形验证码完整代码与详细步骤``````后续更新注册时对密码进行加密

      第一使用 画图软件制作图片 ,文件名就是验证码    ------用户的实体类 import java.util.Date; public class Member {    private in ...

  5. 深浅拷贝, for循环小知识点 str操作 list的删除问题,类型转换

    深浅拷⻉  : lst1 = ["⾦⽑狮王", "紫衫⻰王", "⽩眉鹰王", "⻘翼蝠王"] lst2 = lst1 ...

  6. pytest-参数化2

    import pytesttest_user_data=['linda','sai','tom']@pytest.fixture(scope='module')def login(request): ...

  7. ionic3.0 alipay-base插件移除后会添加多余的链接文件在nodes-modules中,导致再安装其他插件或移除插件时报错问题

    1.报错截图: 2.如图因为nodes-module 文件夹中有多余的链接文件导致报错. 3.解决方法:将该链接文件删除即可.

  8. Django rest_framework 频率控制组件

    频率控制 一.频率控制实现一 from rest_framework.views import APIView from rest_framework.response import Response ...

  9. 【JS学习】慕课网2-7 练习题:制作新按钮,“新窗口打开网站” ,点击打开新窗口。

    要求: 1.新窗口打开时弹出确认框,是否打开 提示: 使用 if 判断确认框是否点击了确定,如点击弹出输入对话框,否则没有任何操作. 2.通过输入对话框,确定打开的网址,默认为 http://www. ...

  10. clickhouse高可用-节点宕机数据一致性方案-热扩容

    1. 集群节点及服务分配 说明: 1.1. 在每个节点上启动两个clickhouse服务(后面会详细介绍如何操作这一步),一个数据分片,一个数据备份,为了确保宕机数据一致性,数据分片和数据备份不能同一 ...