/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 528.0 KiB
#3 Accepted 328ms 2.449 MiB
#4 Accepted 105ms 8.164 MiB
#5 Accepted 2ms 540.0 KiB
#6 Accepted 374ms 2.234 MiB
#7 Accepted 324ms 2.18 MiB
#8 Accepted 60ms 1016.0 KiB
#9 Accepted 293ms 8.051 MiB
#10 Accepted 443ms 7.941 MiB
#11 Accepted 143ms 2.617 MiB
#12 Accepted 207ms 8.027 MiB

Code

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       string s;
       cin>>s;
       int q;
       cin>>q;

       long long rev=0;
       string left;
       string right;
       for(int i=0;i<q;i++)
       {
           long long input;
           cin>>input;

           long long hey;
           char ch;
           if(input==2)
           {
               cin>>hey;
               cin>>ch;

           }

           if(input==1)
           {
               rev++;

           }
           else if(input==2)
           {
               if(rev%2==0)
               {
                   if(hey==1)
                   left.push_back(ch);
                   else
                    right.push_back(ch);
               }
               else
               {
                    if(hey==2)
                   left.push_back(ch);
                   else
                    right.push_back(ch);

               }
           }
       }

       if(rev%2==0)
       {
           reverse(left.begin(),left.end());

           cout<<left;
           cout<<s;
           cout<<right<<endl;
       }
       else
       {
           reverse(right.begin(),right.end());

           cout<<right;

           reverse(s.begin(),s.end());
           cout<<s;
           cout<<left<<endl;

       }
    }
}

Information

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