This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#1022 Digital Library.cpp
91 lines (82 loc) · 1.94 KB
/
#1022 Digital Library.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <sstream>
#include <unordered_map>
#include <set>
using namespace std;
int main() {
size_t n;
string key;
unordered_map<string, set<size_t>> lib[5]; // title, author, keywords, publisher, published year;
if(scanf("%zu", &n) == EOF) return 0;
for(size_t i = 0, id; i < n && scanf("%zu%*c", &id); ++i) {
for(size_t j = 0; j < 5; ++j) {
getline(cin, key);
if(j != 2) lib[j][key].insert(id);
else for(istringstream keys(key); keys >> key; lib[j][key].insert(id));
}
}
if(scanf("%zu", &n) == EOF) return 0;
for(size_t i = 0, type; i < n && scanf("%zu: ", &type); ++i) {
getline(cin, key);
printf("%zu: %s\n", type, key.c_str());
if(!lib[type-1].count(key)) printf("Not Found\n");
else for(const size_t id : lib[type-1][key]) printf("%07zu\n", id);
}
return 0;
}
/*
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].
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
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
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
*/