• + 0 comments

    C++

    include

    include

    include

    include

    include

    include

    using namespace std;

    static stack sString{}; void append(string &s,string appStr){ sString.push(s); s=s+appStr; //cout<<"Appended: "<

    void del( int k, string &s){ sString.push(s); if(s.size()-k >=0) s.erase(s.size()-k,k); //cout<<"Deleted: "<

    void print(int k,const string &s){ cout << s[k-1]<

    void undo(string &s){

    s=sString.top();
    sString.pop();
    //cout<<"After Undo: "<<s<<endl;
    

    }

    vector splitString(string s,string delimiter) { vector out{}; int start=0; int end=s.find(delimiter,start); while(end!=string::npos) { out.push_back(s.substr(start,end-start)); start=end+delimiter.length(); end=s.find(delimiter,start); } out.push_back(s.substr(start)); return out; }

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int q; cin>>q; string out{}; while (q>=0) { string s; getline(cin,s); vector split = splitString(s, " ");

        if(split[0]=="1")
        {
            append(out, split[1]);
        }
        else if(split[0]=="2")
        {
            del(stoi(split[1]), out);
        }
        else if(split[0]=="3")
        {
            print(stoi(split[1]), out);
        }
        else if(split[0]=="4")
        {
            undo(out);
        }
        q--;
    }    
    return 0;
    

    }