Advertisement
FreakSkipper

Containers II

Sep 8th, 2020
1,235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string cont;
  7.     int pilhas_qtd = 0;
  8.     vector<vector<int>> pilhas;
  9.     vector<char> cont_ord;
  10.  
  11.     cin >> cont;
  12.    
  13.     pilhas.push_back(vector<int>());
  14.     for (int i = 0; i < cont.size(); i++) {
  15.         pilhas.back().push_back(cont[i]);
  16.         cont_ord.push_back(cont[i]);
  17.     }
  18.  
  19.     sort(cont_ord.begin(), cont_ord.end());
  20.  
  21.     // vector<int> pilha = pilhas.back();
  22.     while(!pilhas.empty()) {
  23.         for (vector<vector<int>>::iterator it = pilhas.begin(); it != pilhas.end(); it++) {
  24.             if (it->back() == cont_ord.front()) {
  25.                 it->pop_back();
  26.                 cont_ord.erase(cont_ord.begin());
  27.             } else {
  28.                 vector<int> nova_pilha;
  29.                 pilhas.push_back(nova_pilha);
  30.                 pilhas_qtd++;
  31.                
  32.                 while(!it->empty()) {
  33.                     cout << it->back() << endl;
  34.                     if (it->back() != cont_ord.front()) {
  35.                         nova_pilha.push_back(it->back());
  36.                         it->pop_back();
  37.                     } else {
  38.                         it->pop_back();
  39.                         cont_ord.erase(cont_ord.begin());
  40.                         break;
  41.                     }
  42.                 }
  43.             }
  44.  
  45.             if (it->empty()) {
  46.                 pilhas.erase(it);
  47.                 break;
  48.             }
  49.         }
  50.     }
  51.  
  52.     cout << pilhas_qtd + 1 << endl;
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement