Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- string cont;
- int pilhas_qtd = 0;
- vector<vector<int>> pilhas;
- vector<char> cont_ord;
- cin >> cont;
- pilhas.push_back(vector<int>());
- for (int i = 0; i < cont.size(); i++) {
- pilhas.back().push_back(cont[i]);
- cont_ord.push_back(cont[i]);
- }
- sort(cont_ord.begin(), cont_ord.end());
- // vector<int> pilha = pilhas.back();
- while(!pilhas.empty()) {
- for (vector<vector<int>>::iterator it = pilhas.begin(); it != pilhas.end(); it++) {
- if (it->back() == cont_ord.front()) {
- it->pop_back();
- cont_ord.erase(cont_ord.begin());
- } else {
- vector<int> nova_pilha;
- pilhas.push_back(nova_pilha);
- pilhas_qtd++;
- while(!it->empty()) {
- cout << it->back() << endl;
- if (it->back() != cont_ord.front()) {
- nova_pilha.push_back(it->back());
- it->pop_back();
- } else {
- it->pop_back();
- cont_ord.erase(cont_ord.begin());
- break;
- }
- }
- }
- if (it->empty()) {
- pilhas.erase(it);
- break;
- }
- }
- }
- cout << pilhas_qtd + 1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement