/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 560.0 KiB
#2 Accepted 3ms 328.0 KiB
#3 Accepted 382ms 32.789 MiB
#4 Accepted 602ms 37.145 MiB
#5 Accepted 2ms 536.0 KiB
#6 Accepted 441ms 10.973 MiB
#7 Accepted 397ms 10.434 MiB
#8 Accepted 75ms 7.809 MiB
#9 Accepted 631ms 37.93 MiB
#10 Accepted 754ms 36.863 MiB
#11 Accepted 187ms 37.219 MiB
#12 Accepted 625ms 37.82 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define print(v) for(auto &u:v) cout << u << " "
#define printp(v) for(auto e:v) cout<<e.first<<" "<<e.second<<endl;
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define printl(li) for(auto &u:li) cout << u;
 
void solve()
{ 
   string str; cin >> str;
   list <char> li;
   for(int i=0; i<str.size(); i++) li.pb(str[i]);
   int q; cin >> q;
   bool flag = true;
   int ct=0;
   while(q--){
      int check; cin >> check;

      if(check==2)
      {
         int d; cin >> d;
         char ch; cin >> ch;
         if(flag = true && ct%2==0)
         {
            d==1 ? li.push_front(ch) : li.push_back(ch);

           
         }
         else
         {
            d==1 ? li.push_back(ch) : li.push_front(ch);
         }
         flag = true;
      }
      else if(check == 1){
         flag = false;
         ct++;
      }

   }

  if(ct%2!=0)
  {
      li.reverse();
      printl(li);
      cout << endl;
  }
  else 
  {
      printl(li);
      cout << endl;
  }
  
 
}
 
int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1; cin >> t;
    while(t--)
    {
       solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1088 Mr. Heart's String Challenge
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-07 10:13:01
Judged At
2024-11-11 02:55:36
Judged By
Score
100
Total Time
754ms
Peak Memory
37.93 MiB