Advertisement
Rock-Lee

I NEED TO TRY MORE

May 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string u;
  7.     cin >> u;
  8.     string resp = "";
  9.  
  10.     deque<char> s;
  11.  
  12.     for(int i = 0; i < u.size(); i++) {
  13.         if(u.at(i) == 'a') {
  14.             resp += u.at(i);
  15.         }
  16.         else {
  17.             if(s.empty()) s.push_back(u.at(i));
  18.             else if(u.at(i) < s.back()) resp += u.at(i);
  19.             else s.push_back(u.at(i));
  20.         }
  21.     }
  22.     while(!s.empty()) {
  23.         resp += s.front();
  24.         s.pop_back();
  25.     }
  26.  
  27.     cout << resp << endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement