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 (≤) 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 (≤) 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

题意:

  模拟一个图书查询系统

思路:

  模拟

Code:

  1 #include <bits/stdc++.h>
2
3 using namespace std;
4
5 struct Book {
6 string id;
7 string title;
8 string author;
9 set<string> keywords;
10 string publisher;
11 string published_year;
12 };
13
14 bool cmp(Book a, Book b) { return a.id < b.id; }
15
16 int main() {
17 int n;
18 cin >> n;
19 getchar();
20 string temp;
21 vector<Book> books(n);
22 for (int i = 0; i < n; ++i) {
23 getline(cin, books[i].id);
24 getline(cin, books[i].title);
25 getline(cin, books[i].author);
26 getline(cin, temp);
27 getline(cin, books[i].publisher);
28 getline(cin, books[i].published_year);
29 int last = 0, pos;
30 set<string> keywords;
31 while (temp.find(' ', last) != string::npos) {
32 pos = temp.find(' ', last);
33 string keyword = temp.substr(last, pos - last);
34 books[i].keywords.insert(keyword);
35 last = pos + 1;
36 }
37 books[i].keywords.insert(temp.substr(last));
38 }
39 sort(books.begin(), books.end(), cmp);
40 int m;
41 cin >> m;
42 getchar();
43 string query;
44 for (int i = 0; i < m; ++i) {
45 getline(cin, query);
46 cout << query << endl;
47 int flag = 0;
48 switch (query[0] - '0') {
49 case 1:
50 temp = query.substr(3);
51 for (int j = 0; j < n; ++j) {
52 if (books[j].title == temp) {
53 cout << books[j].id << endl;
54 flag = 1;
55 }
56 }
57 break;
58 case 2:
59 temp = query.substr(3);
60 for (int j = 0; j < n; ++j) {
61 if (books[j].author == temp) {
62 cout << books[j].id << endl;
63 flag = 1;
64 }
65 }
66 break;
67 case 3:
68 temp = query.substr(3);
69 for (int j = 0; j < n; ++j) {
70 for (string s : books[j].keywords) {
71 if (s == temp) {
72 cout << books[j].id << endl;
73 flag = 1;
74 break;
75 }
76 }
77 }
78 break;
79 case 4:
80 temp = query.substr(3);
81 for (int j = 0; j < n; ++j) {
82 if (books[j].publisher == temp) {
83 cout << books[j].id << endl;
84 flag = 1;
85 }
86 }
87 break;
88 case 5:
89 temp = query.substr(3);
90 for (int j = 0; j < n; ++j) {
91 if (books[j].published_year == temp) {
92 cout << books[j].id << endl;
93 flag = 1;
94 }
95 }
96 break;
97 default:
98 break;
99 }
100 if (flag == 0) cout << "Not Found" << endl;
101 }
102
103 return 0;
104 }

1022 Digital Library的更多相关文章

  1. PAT 1022 Digital Library[map使用]

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

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

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

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

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

  4. 1022 Digital Library (30 分)

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

  5. 1022 Digital Library——PAT甲级真题

    1022 Digital Library A Digital Library contains millions of books, stored according to their titles, ...

  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. PAT 甲级 1022 Digital Library

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

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

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

  10. PTA (Advanced Level) 1022 Digital Library

    Digital Library A Digital Library contains millions of books, stored according to their titles, auth ...

随机推荐

  1. Java基础语法:运算符

    Java 运算符(operator)根据功能分类: 算术运算符:+,-,*,/,%,++,-- 赋值运算符:= 关系运算符:>,<,>=,<=,==,!=,instanceof ...

  2. 用代码来实践Web缓存

    Web缓存是可以自动保存常见文档副本的HTTP设备.当Web请求抵达缓存时,如果本地有"已缓存的副本",就可以从本地存储设备而不是原始服务器中提取这个文档. 上面是<HTTP ...

  3. ServiceMesh

    传统微服务架构 在微服务模式下,企业内部服务少则几个到几十个,多则上百个,每个服务一般都以集群方式部署,这时自然产生两个问题: 一.服务发现:服务的消费方(Consumer)如何发现服务的提供方(Pr ...

  4. 面试系列二:精选大数据面试真题JVM专项-附答案详细解析

    公众号(五分钟学大数据)已推出大数据面试系列文章-五分钟小面试,此系列文章将会深入研究各大厂笔面试真题,并根据笔面试题扩展相关的知识点,助力大家都能够成功入职大厂! 大数据笔面试系列文章分为两种类型: ...

  5. 10. vue之webpack打包详解

    一.什么是webpack webpack官网给出的定义是 本质上,webpack 是一个现代 JavaScript 应用程序的静态模块打包器(module bundler).当 webpack 处理应 ...

  6. 在不使用外延层的同轴半绝缘衬底材料上制作4H-SIC横向双重注入金属氧化物半导体场效应晶体管

    在不使用外延层的同轴半绝缘衬底材料上制作4H-SIC横向双重注入金属氧化物半导体场效应晶体管 杂志:日本应用物理杂志   在不使用外延层在同轴的半绝缘SIC衬底上制作4H-SIC横向双重注入金属氧化物 ...

  7. Navicat 121版本激活工具

    以下是工具的链接: https://github.com/DoubleLabyrinth/navicat-keygen/blob/windows/README_FOR_WINDOWS.zh-CN.md ...

  8. Visual Studio添加引用的方式

  9. c++ 反汇编 异常处理

    c++异常处理 int main(){ try { throw 1; } catch ( int e ) { printf("catch int\r\n"); } catch ( ...

  10. effective解读-第一条 静态工厂创建对象代替构造器

    好处 有名称,能见名知意.例如BigInteger的probablePrime方法 享元模式.单例模式中使用 享元模式:创建对象代价很高,重复调用已有对象,例如数据库连接等.享元模式是单例模式的一个拓 ...