Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main() {
- string u;
- cin >> u;
- string resp = "";
- deque<char> s;
- for(int i = 0; i < u.size(); i++) {
- if(u.at(i) == 'a') {
- resp += u.at(i);
- }
- else {
- if(s.empty()) s.push_back(u.at(i));
- else if(u.at(i) < s.back()) resp += u.at(i);
- else s.push_back(u.at(i));
- }
- }
- while(!s.empty()) {
- resp += s.front();
- s.pop_back();
- }
- cout << resp << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement