• + 0 comments
    my c++ sol:
    
    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <stack>
    using namespace std;
    
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        string s="";
        stack<string> st;
        int n;
        cin>>n;
        for(int i =0; i< n; i++)
        {
            int k =0;
            cin>>k;
            if(k==1)
            {
                string str;
                cin>>str;
                st.push(s);
                s.append(str);
            }
            if(k==2)//last k character
            {
                int no;
                cin>>no;
                st.push(s);
                while(no>0)
                {
                    s.pop_back();
                    no--;
                }
            }
            if(k==3)//print kth char
            {
                int h;
                cin>>h;
                cout<<s[h-1]<<endl;
            }
            else if (k == 4) {
                if (!st.empty()) {
                    s = st.top();
                    st.pop();
                }
            }
        }
        return 0;
    }