/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 2ms 332.0 KiB
#3 Accepted 611ms 2.496 MiB
#4 Accepted 190ms 8.023 MiB
#5 Accepted 2ms 540.0 KiB
#6 Accepted 685ms 2.188 MiB
#7 Accepted 664ms 2.117 MiB
#8 Accepted 119ms 1.172 MiB
#9 Accepted 299ms 8.094 MiB
#10 Accepted 469ms 8.113 MiB
#11 Accepted 148ms 2.668 MiB
#12 Accepted 218ms 8.035 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-10-03 13:07:55
Judged By
Score
100
Total Time
685ms
Peak Memory
8.113 MiB