-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1022 Digital Library.cpp
99 lines (98 loc) · 1.74 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
92
93
94
95
96
97
98
99
# include <iostream>
# include <functional>
# include <vector>
# include <algorithm>
#include<math.h>
#include<string>
#include<cstring>
#include<iterator>
#include<iomanip>
#include<numeric>
#include<map>
#include<unordered_map>
#include<set>
#include<limits.h>
#include<queue>
#include<stack>
using namespace std;
struct book {
int id;
string title, author, keywords, publisher;
int year;
bool operator<(book b) {
return id < b.id;
}
};
vector<book> books;
int main()
{
int n;
scanf("%d", &n);
books.resize(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &books[i].id);
cin.get();
getline(cin, books[i].title, '\n');
getline(cin, books[i].author, '\n');
getline(cin, books[i].keywords, '\n');
getline(cin, books[i].publisher, '\n');
scanf("%d", &books[i].year);
cin.get();
}
sort(books.begin(), books.end());
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int cmd, ct(0);
string des;
cin >> cmd;
cin.get();
cin.get();
getline(cin, des, '\n');
printf("%d: %s\n", cmd, des.c_str());
if (cmd == 1) {
for (auto &bk : books) {
if (bk.title == des) {
printf("%07d\n", bk.id);
ct++;
}
}
}
else if (cmd == 2) {
for (auto &bk : books) {
if (bk.author == des) {
printf("%07d\n", bk.id);
ct++;
}
}
}
else if (cmd == 3) {
for (auto &bk : books) {
if (bk.keywords.find(des) != -1) {
printf("%07d\n", bk.id);
ct++;
}
}
}
else if (cmd == 4) {
for (auto &bk : books) {
if (bk.publisher ==des){
printf("%07d\n", bk.id);
ct++;
}
}
}
else {
int y = atoi(des.c_str());
for (auto &bk : books) {
if (bk.year == y){
printf("%07d\n", bk.id);
ct++;
}
}
}
if (ct == 0)
printf("Not Found\n");
}
return 0;
}