Advertisement
artemgf

Монетки

Nov 29th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. vector<pair<int,int>>all;
  2.     int n;
  3.     cin >> n;
  4.     int prom;
  5.     int last = -1;
  6.     int verx = -1;
  7.     bool was = false;
  8.     vector <int>answ;
  9.     for (int i = 1; i <= n; i++)
  10.     {
  11.         cin >> prom;
  12.         if (prom > 0)
  13.         {
  14.             last = i-1;
  15.             if (!was)
  16.             {
  17.                 verx = last;
  18.             }
  19.             was = 0;
  20.         }
  21.         else
  22.         {
  23.             if (prom == 0)
  24.             {
  25.                 for (int j = i-2; j >= 0; j--)
  26.                 {
  27.                     if (all[j].first > 0&&all[j].first!=0)
  28.                         all[j].second *= 2;
  29.                 }
  30.             }
  31.             else
  32.             {
  33.                 was = 1;
  34.                 all[verx].second--;
  35.                 answ.push_back(all[verx].first);
  36.                 bool u = false;
  37.                 if (all[verx].second == 0)
  38.                     u = 1;
  39.                 bool p = false;
  40.                 for (int j = verx - 1; j >= 0; j--)
  41.                 {
  42.                     if (all[j].first > 0 && all[j].first != 0)
  43.                     {
  44.                         if (u)
  45.                             last = j;
  46.                         verx = j;
  47.                         p = 1;
  48.                         break;
  49.                     }
  50.                 }
  51.                 if (!p)
  52.                     if(!u)
  53.                     verx = last;
  54.                     else
  55.                     {
  56.                         verx = -1;
  57.                         last = -1;
  58.                     }
  59.             }
  60.         }
  61.         all.push_back({ prom, 1 });
  62.     }
  63.  
  64.     for (int i = 0; i < answ.size(); i++)
  65.     {
  66.         cout << answ[i] << endl;
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement