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. qrcode.js生成二维

    使用到qrcode.js生成二维码 pako.js压缩字符串:https://github.com/nodeca/pako 参照代码如下: <!DOCTYPE HTML PUBLIC " ...

  2. HTML5: HTML5 内联 SVG

    ylbtech-HTML5: HTML5 内联 SVG 1.返回顶部 1. HTML5 内联 SVG HTML5 支持内联 SVG. 什么是SVG? SVG 指可伸缩矢量图形 (Scalable Ve ...

  3. (18)C++ string和标准模板库

    一.stringl类 1.string构造函数 string a1("abc");//初始化字符串 cout<<a1<<endl;//abc , '#'); ...

  4. 测试过程中bug分类

    测试的核心任务是发现bug.在这之前是分析需求,之后是跟踪bug.跳出具体的项目来看,所有的bug无非是以下五大类. 软件没有实现应该实现的功能:如指定的登录功能. 软件出现了本应该避免的错误:如用户 ...

  5. python学习笔记:循环语句——while、for

    python中有两种循环,while和for,两种循环的区别是,while循环之前,先判断一次,如果满足条件的话,再循环,for循环的时候必须有一个可迭代的对象,才能循环,比如说得有一个数组.循环里面 ...

  6. 清除浮动最有效的css写法

    说起来呢,基本上只要你给容器div加了float的属性,就需要清除浮动来使页面显示正常,那么,到底有什么方法可以让浮动轻松清除呢? 可以用display:flex;替代,但是它对IE8,9支持不是很好 ...

  7. pip安装任何包都出现问题

    <!DOCTYPE html> { margin: 0; padding: 0; } body { background: url(images/body_bg.png) repeat-x ...

  8. neo4j简单学习

    阅读更多 背景 最近在一些论坛或者新闻里看到了neo4j,一种擅长处理图形的数据库. 据说非常适合做一些join关系型的查询,所以抽空也看了下相关文档,给自己做个技术储备. 过程 深入学习之前,先在网 ...

  9. position: relative 和 position: absoution 的详解

    position属性指定一个元素(静态的,相对的,绝对或固定)的定位方法的类型 relative:生成相对定位的元素,相对于其正常位置进行定位. 对应下图的偏移 absolute: 生成绝对定位的元素 ...

  10. SpringMVC学习(6):数据验证

    在系列(4).(5)中我们展示了如何绑定数据,绑定完数据之后如何确保我们得到的数据的正确性?这就是我们本篇要说的内容 -> 数据验证. 这里我们采用Hibernate-validator来进行验 ...