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 (<=10000) 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<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<set>
using namespace std;
map<string, set<int>> mp1, mp2, mp3, mp4, mp5;
void show(map<string, set<int>> &mp, string &key){
set<int> ::iterator it;
int find = ;
for(it = mp[key].begin(); it != mp[key].end(); it++){
printf("%07d\n", *it);
find = ;
}
if(find == )
printf("Not Found\n");
}
int main(){
int N, M, id;
string ss, ss2;
scanf("%d ", &N);
for(int i = ; i < N; i++){
scanf("%d ", &id);
getline(cin, ss);
mp1[ss].insert(id);
getline(cin, ss);
mp2[ss].insert(id);
while(cin >> ss){
char c = getchar();
mp3[ss].insert(id);
if(c == '\n')
break;
}
getline(cin, ss);
mp4[ss].insert(id);
getline(cin, ss);
mp5[ss].insert(id);
}
scanf("%d ", &M);
for(int i = ; i < M; i++){
getline(cin, ss2);
cout << ss2 + "\n";
ss = ss2.substr();
if(ss2[] == ''){
show(mp1, ss);
}else if(ss2[] == ''){
show(mp2, ss);
}else if(ss2[] == ''){
show(mp3, ss);
}else if(ss2[] == ''){
show(mp4, ss);
}else if(ss2[] == ''){
show(mp5, ss);
}
}
cin >> N;
return ;
}

总结:

1、题意:先输入书的id、名字、作者、关键词、出版社、出版时间。然后根据除书id以外的信息来查询书的id。注意其中书的关键词在输入时为一行字符串,其实是多个关键词以空格分开。由于一个信息可能对多本书(一个出版社有多本书...),且在查询结果时需要有序输出,所以可以使用 map<string ,  set<int>> 存储。

2、对于下面信息的第4行,需要分别读出每个单词,可以这么做

1111111
The Testing Book
Yue Chen
test code debug sort keywords
ZUCS Print
2011

  while(cin >> ss){
    char c = getchar();
    mp3[ss].insert(id);
    if(c == '\n')
    break;
  }

而当要用cin 读入带空格的一行时,可以 getline(cin , str);

3、在函数传参时,如果参数中有map、set、string等,应该传引用,否则可能会超时。

												

A1022. Digital Library的更多相关文章

  1. PAT甲级——A1022 Digital Library

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

  2. 【算法笔记】A1022 Digital Library

    题意 输入n本书的信息:id,书名,作者,关键字,出版社,出版年份.搜索图书,输出id. 思路 定义5个map<string, set<int> >,分别存放Title, Au ...

  3. [PAT] A1022 Digital Library

    [题目大意] 给出几本书的信息,包括编号,名字,出版社,作者,出版年份,关键字:然后给出几个请求,分别按照1->名字,2->出版社等对应信息查询符合要求的书的编号. [思路] 模拟. [坑 ...

  4. 1022. Digital Library (30)

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

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

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

  6. PAT1022.:Digital Library

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

  7. PAT 甲级 1022 Digital Library

    https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...

  8. PAT 1022 Digital Library[map使用]

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

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

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

随机推荐

  1. Facebook React 和 Web Components(Polymer)对比优势和劣势

    目录结构 译者前言 Native vs. Compiled 原生语言对决预编译语言 Internal vs. External DSLs 内部与外部 DSLs 的对决 Types of DSLs - ...

  2. [UWP 自定义控件]了解模板化控件(4):TemplatePart

    1. TemplatePart TemplatePart(部件)是指ControlTemplate中的命名元素.控件逻辑预期这些部分存在于ControlTemplate中,并且使用protected ...

  3. VMware workstation运维实践系列博客导航

    第一章:VMware workstation虚拟化1.1 VMware workstation计算网络存储介绍1.2 VMware workstation其他功能特性介绍1.3 VMware work ...

  4. Linux下selinux简单梳理

    在linux环境下执行某些程序时,偶尔会遇到来一个关于selinux的强制模式不可执行的情况,这种情况下需要关闭selinux或者将enforcing改为permissive模式后才能进行执行.sel ...

  5. B. Equations of Mathematical Magic

    思路 打表找规律,发现结果是,2的(a二进制位为1总数)次方 代码 #include<bits/stdc++.h> using namespace std; #define ll long ...

  6. PairProject 电梯调度 【附加题】

    [附加题] 改进电梯调度的interface 设计, 让它更好地反映现实, 更能让学生练习算法, 更好地实现信息隐藏和信息共享. 目前的设计有什么缺点, 你会如何改进它? 1.之前判断电梯是否闲置的函 ...

  7. 软件工程(五)UML

    UML 统一建模语言,又称标准建模语言.是用来对软件密集系统进行可视化建模的一种语言.包括UML语义和UML表示法两个元素. UMl图由事物和关系组成,事物:UML模型中最基本的构成元素,是具有代表性 ...

  8. my项目的总结2015.8.26编

    这已经是上上个星期的事了,现在回顾一下: 负责的模块是"my",更精准的说应该是my里面的个人信息管理 由于项目分域,模块已经分好了,涉及到的只是在现有的基础上解决分域后遗留的历史 ...

  9. eclipse jee使用

    eclipse jee 安装 已经安装过elipse for Java,不知道会不会冲突? 查过,原来,你就算安装多个elipse for java都没事,更不用说jee.我选择的是eclipse-i ...

  10. HashMap为什么存取效率那么高?

    HashMap为什么存取效率那么高? 1.Hash 也叫散列.哈希. 主要用于信息安全领域中的算法,把长度不同的信息转化为杂乱的128位的编码,找到一种数据内容与地址之间的映射关系. 注意:不同的输入 ...