/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 536.0 KiB
#2 Accepted 2ms 480.0 KiB

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
Pretest
Problem
P1088 Mr. Heart's String Challenge
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 16:07:35
Judged At
2024-11-11 03:01:37
Judged By
Score
20
Total Time
2ms
Peak Memory
536.0 KiB