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. CSS的定位布局(position)

    定位 static(默认值) 没有开启定位 relative 相对定位的性质 包含块(containing block)概念 没有开启定位时包含块就是当前元素最近的祖先块元素 开启绝对定位后的元素包含 ...

  2. AJAX基本操作

    XMLHttpRequest对象: XMLHttpRequest 是 AJAX 的基础.所有现代浏览器均支持 XMLHttpRequest 对象(IE5 和 IE6 使用 ActiveXObject) ...

  3. 什么原因才是阻碍Linux桌面发展的罪魁祸首

    我大概2000年上大学在宿舍开始玩Linux,到现在20年了!也算是最早一批痴迷于Linux桌面用户啦!记得当时的毕业设计BBS论坛开发就是在Mandrake Linux(后改名Mandriva,一种 ...

  4. HDFS的上传流程以及windows-idea操作文件上传的注意

    HDFS的上传流程 命令:hdfs dfs -put xxx.wmv /hdfs的文件夹 cd进入到要上传文件的当前目录,再输入hdfs命令上传,注意-put后tab可以自动补全, 最后加上你要上传到 ...

  5. 一键自签本地 TLSv3 多域名 SAN 域名证书工具 HTTPS(最新版 Chrome 浏览器策略测试通过)

    一键自动生成本地自签名SAN域名证书工具 原生OpenSSL生成自签名SAN CA域名(V3签名),在Linux.MacOS系统下签发测试通过. 用于一键快速生成开发和测试场景证书,内部平台授权和私有 ...

  6. MyBatis、Spring、SpringMVC 源码下载地址

    MyBatis.Spring.SpringMVC 源码下载地址 github mybatis https://github.com/fengyu415/MyBatis-Learn.git spring ...

  7. 11、Spring教程之声明式事务

    1.回顾事务 事务在项目开发过程非常重要,涉及到数据的一致性的问题,不容马虎! 事务管理是企业级应用程序开发中必备技术,用来确保数据的完整性和一致性. 事务就是把一系列的动作当成一个独立的工作单元,这 ...

  8. 快速上手阿里云oss SDK

    使用阿里云oss SDK 依赖安装: pip install oss2 pip install aliyun-python-sdk-sts 版本最好是 2.7.5 或以上 如果要开启 crc64 循环 ...

  9. 基于k8s的集群稳定架构-转载

    基于k8s的集群稳定架构-转载 前言 我司的集群时刻处于崩溃的边缘,通过近三个月的掌握,发现我司的集群不稳定的原因有以下几点: 1.发版流程不稳定 2.缺少监控平台[最重要的原因] 3.缺少日志系统 ...

  10. [BFS]电子老鼠闯迷宫

    电子老鼠闯迷宫 Description 如下图12×12方格图,找出一条自入口(2,9)到出口(11,8)的最短路径. Input Output Sample Input 12 //迷宫大小 2 9 ...