Advertisement
LEGEND2004

Maximum Frequency Stack

Feb 12th, 2023
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     string str;
  5.     int x , maxx = 0;
  6.     map<int , stack<int> > s;
  7.     map<int , int> say;
  8.     while(cin >> str){
  9.         if(str == "push"){
  10.             cin >> x;
  11.             say[x]++;
  12.             s[say[x]].push(x);
  13.             maxx = max(maxx , say[x]);
  14.             continue;
  15.         }
  16.         say[s[maxx].top()]--;
  17.         cout << s[maxx].top() << endl;
  18.         s[maxx].pop();
  19.         while(s[maxx].empty()){
  20.             maxx--;
  21.             if(!maxx)
  22.                 break;
  23.         }
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement