/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 169ms 32.867 MiB
#4 Accepted 328ms 36.926 MiB
#5 Accepted 2ms 532.0 KiB
#6 Accepted 201ms 10.973 MiB
#7 Accepted 188ms 10.293 MiB
#8 Accepted 70ms 7.77 MiB
#9 Accepted 331ms 37.715 MiB
#10 Accepted 421ms 36.832 MiB
#11 Accepted 102ms 37.059 MiB
#12 Accepted 312ms 37.863 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-09-07 10:13:01
Judged By
Score
100
Total Time
421ms
Peak Memory
37.863 MiB