/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 316.0 KiB
#3 Accepted 383ms 3.352 MiB
#4 Accepted 200ms 8.051 MiB
#5 Accepted 2ms 324.0 KiB
#6 Accepted 404ms 2.34 MiB
#7 Accepted 380ms 1.961 MiB
#8 Accepted 69ms 1.062 MiB
#9 Accepted 249ms 8.516 MiB
#10 Accepted 351ms 8.008 MiB
#11 Accepted 109ms 3.66 MiB
#12 Accepted 218ms 9.074 MiB

Code

#include<bits/stdc++.h>
using namespace std;

int main() {
    int T;
    cin >> T;
    
    while (T--) {
        string s;
        cin >> s;
        
        deque<char> front(s.begin(), s.end());
        deque<char> back;
        
        int q;
        cin >> q;
        
        bool reversed = false; 
        
        while (q--) {
            int queryType;
            cin >> queryType;
            
            if (queryType == 1) {
                reversed = !reversed;  
            } 
            
            else {
                int d;
                char C;
                cin >> d >> C;
                
                if (reversed) {
                    if (d == 1) {
                        back.push_back(C);  
                    } else {
                        front.push_front(C);  
                    }
                } else {
                    if (d == 1) {
                        front.push_front(C); 
                    } else {
                        back.push_back(C);  
                    }
                }
            }
        }
        
        
        if (reversed) {
           
            for (auto it = back.rbegin(); it != back.rend(); ++it) {
                cout << *it;
            }
            for (auto it = front.rbegin(); it != front.rend(); ++it) {
                cout << *it;
            }
        } else {
           
            for (auto ch : front) {
                cout << ch;
            }
            for (auto ch : back) {
                cout << ch;
            }
        }
        cout << endl;
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1088 Mr. Heart's String Challenge
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 16:08:02
Judged At
2024-11-11 03:01:36
Judged By
Score
100
Total Time
404ms
Peak Memory
9.074 MiB