/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 508.0 KiB
#2 Accepted 2ms 516.0 KiB
#3 Accepted 770ms 3.234 MiB
#4 Accepted 344ms 8.227 MiB
#5 Accepted 2ms 328.0 KiB
#6 Accepted 846ms 2.242 MiB
#7 Accepted 737ms 1.992 MiB
#8 Accepted 156ms 1.035 MiB
#9 Accepted 500ms 8.391 MiB
#10 Accepted 620ms 8.176 MiB
#11 Accepted 177ms 3.574 MiB
#12 Accepted 407ms 9.246 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-11-11 03:01:35
Judged By
Score
100
Total Time
846ms
Peak Memory
9.246 MiB