-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathBookstack.cpp
More file actions
39 lines (36 loc) · 955 Bytes
/
Bookstack.cpp
File metadata and controls
39 lines (36 loc) · 955 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin>>q;
stack<pair<int,string> > bookInfo;
stack<int> minStack;
while(q--){
int n;
cin>>n;
if(n != -1) {
string bookName;
cin>>bookName;
if(n == 0) {
continue;
}
bookInfo.push({n,bookName});
if(minStack.empty() or n<=minStack.top()){
minStack.push(n);
}
} else{
int minBookRemoval = 0;
int minValue = minStack.top();
while(bookInfo.top().first != minValue){
minBookRemoval++;
bookInfo.pop();
}
cout<<minBookRemoval<<" "<<bookInfo.top().second<<endl;
bookInfo.pop();
minStack.pop();
}
}
return 0;
}