Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include<iostream>
  2. #include <stack>
  3. #include <queue>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. using namespace std;
  8. int main()
  9. {
  10.     queue <pair <string, long> > stones;
  11.     stack < pair <string, long> > whiteStones;
  12.     vector <long> num;
  13.     string str;
  14.     long n, k;
  15.  
  16.     cin>>n;
  17.  
  18.     for(int i = 0; i < n; i++)
  19.     {
  20.         cin>>str;
  21.         cin>>k;
  22.         stones.push(make_pair(str, k));
  23.     }
  24.  
  25.     while(!stones.empty())
  26.        {
  27.            long sum = 0;
  28.            if(stones.front().first == "white")
  29.             {
  30.              whiteStones.push(make_pair("white", stones.front().second));
  31.              stones.pop();
  32.             }else if(stones.front().first == "green")
  33.                 {
  34.                     for(int i =0 ; i < stones.front().second; i++)
  35.                     {
  36.                         sum += whiteStones.top().second;
  37.                         whiteStones.pop();
  38.                     }
  39.                     whiteStones.push(make_pair("white", sum));
  40.                     stones.pop();
  41.                 }else if(stones.front().first == "blue")
  42.                     {   int maxi = 0;
  43.                         for(int i =0 ; i < stones.front().second; i++)
  44.                         {
  45.                             if(maxi < whiteStones.top().second)
  46.                             {
  47.                                 maxi = whiteStones.top().second;
  48.                             }
  49.                             whiteStones.pop();
  50.                         }
  51.                        whiteStones.push(make_pair("white", maxi));
  52.                        stones.pop();
  53.                     }
  54.             }
  55.  
  56.     while(!whiteStones.empty())
  57.     {
  58.         num.push_back(whiteStones.top().second);
  59.         whiteStones.pop();
  60.     }
  61.  
  62.     reverse(num.begin(),num.end());
  63.     for(int i = 0; i < num.size(); i++)
  64.     {
  65.         cout<<num[i]<<" ";
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement