• + 0 comments

    My C++ Solution:

    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int q=0;
        cin >> q;
        string s ="";
        stack<string> v;
        v.push(s);
        for(int i=0; i<q; i++){
            int op = 0;string ss;
            cin >> op;
            if(op != 4)cin >> ss;
            switch (op) {
                case 1:
                   s+=ss;
                   v.push(s);
                   break;
                case 2:
                    s = s.substr(0, s.length() - stoi(ss));
                    v.push(s);
                    break;
                 case 3:
                    cout << v.top()[stoi(ss)-1]<<endl;
                    break;
                case 4:
                    v.pop();
                    s = v.top();
                    break;
            }
        }
        
        return 0;
    }