Blame view
SearchingSortingandBasicDataStructures/Stack/Problem3/GeekAndBooks.cpp
846 Bytes
eb0b70f67
![]() |
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 |
// // Created by ronal on 2/11/2023. // Problem Description Link. // https://practice.geeksforgeeks.org/problems/geek-and-books/0 #include <bits/stdc++.h> using namespace std; int main() { stack<int> Stak; int tests, size, value; string type; cin >> tests; for(int i = 0; i < tests; i++){ cin >> size; for(int j = 0; j < size; j++){ cin >> type; if(type.compare("place") == 0){ cin >> value; Stak.push(value); }else{ if(Stak.empty()){ cout << "-1 "; }else{ cout << Stak.top() << " "; Stak.pop(); } } } while(!Stak.empty()){ Stak.pop(); } cout << " "; } return 0; } |