Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stack>
- #include<vector>
- using namespace std;
- class mod{
- int module;
- int price;
- public:
- mod(int m, int p){
- module = m;
- price = p;
- }
- int getPrice(){
- return price;
- }
- };
- int main(){
- int n;
- cin>>n;
- stack<mod> s;
- int choice, price;
- vector<int> v;
- for(int i = 0; i < n; i++){
- cin>>choice;
- if(choice == 2){
- cin>>price;
- mod m(choice, price);
- s.push(m);
- }
- else{
- mod buy = s.top();
- v.push_back(buy.getPrice());
- s.pop();
- }
- }
- for(int i = 0; i < v.size(); i++){
- cout<<v[i]<<endl;
- }
- }
Add Comment
Please, Sign In to add comment