-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBorrowers.cpp
80 lines (74 loc) · 1.39 KB
/
Borrowers.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
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
struct Node
{
string author;
int status;
};
vector<string> node;
map<string, Node> books;
bool cmp(string a, string b)
{
if(a != b)
return a < b;
else
return books[a].author < books[b].author;
}
int main()
{
freopen("data.in", "r", stdin);
string line;
while(getline(cin, line) && line != "END")
{
string author = line.substr(line.find_first_of("\"")+1);
string book_name = line.substr(0, line.find_last_of("\"") + 1);
node.push_back(book_name);
books[book_name].author = author;
books[book_name].status = 1;
}
sort(node.begin(), node.end(), cmp);
string centences;
while(cin >> line)
{
if(line == "END")
break;
if(line == "BORROW")
{
getchar();
getline(cin, centences);
books[centences].status = 0;
}
if(line == "RETURN")
{
getchar();
getline(cin, centences);
books[centences].status = -1;
}
if(line == "SHELVE")
{
for(int i = 0; i < node.size(); i++)
{
if(books[node[i]].status == -1)
{
int j;
for(j = i; j >= 0; j--)
{
if(books[node[j]].status == 1)
break;
}
if(j > -1)
cout << "Puts" << node[i] << "after" << node[j] << endl;
else
cout << "Puts" << node[i] <<"first" << endl;
books[node[i]].status = 1;
}
}
cout << "END" << endl;
}
}
return 0;
}