/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 548.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 336ms 3.395 MiB
#4 Accepted 170ms 8.098 MiB
#5 Accepted 2ms 324.0 KiB
#6 Accepted 375ms 2.332 MiB
#7 Accepted 360ms 1.957 MiB
#8 Accepted 68ms 1.062 MiB
#9 Accepted 238ms 8.301 MiB
#10 Accepted 318ms 8.141 MiB
#11 Accepted 95ms 3.578 MiB
#12 Accepted 190ms 9.051 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:05
Judged At
2024-10-03 13:08:49
Judged By
Score
100
Total Time
375ms
Peak Memory
9.051 MiB