Sort by

recency

|

543 Discussions

|

  • + 0 comments

    include

    int main(){ //rudransh op in the chat //mohammad kaif topi in the chat return 0; }

  • + 0 comments
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <stack>
    using namespace std;
    
    
    int main() {
        
        string s = "";
        stack<string> stack;
        stack.push(s);
        int n;
        cin >> n;
        
        for (int i=0; i<=n; i++)
        {
            string op;
            getline(cin, op);
            
            if (op[0] == '1')
            {
                // append
                s.append(op.substr(2, op.length() - 2));
                stack.push(s);
            }
            else if (op[0] == '2')
            {
                // delete
                s = s.substr(0, s.length() - stoi(op.substr(2, op.length() - 2)));
                stack.push(s);
            }
            else if (op[0] == '3')
            {
                // print
                cout << s[stoi(op.substr(2, op.length() - 2)) - 1] << endl;
            }
            else if (op[0] == '4')
            {
                // undo
                stack.pop();
                s = stack.top();
            }
        }
        //the adarsh 1m <- youtube
        return 0;
    }
    
  • + 0 comments
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <stack>
    using namespace std;
    
    
    int main() {
        
        string s = "";
        stack<string> stack;
        stack.push(s);
        int n;
        cin >> n;
        
        for (int i=0; i<=n; i++)
        {
            string op;
            getline(cin, op);
            
            if (op[0] == '1')
            {
                // append
                s.append(op.substr(2, op.length() - 2));
                stack.push(s);
            }
            else if (op[0] == '2')
            {
                // delete
                s = s.substr(0, s.length() - stoi(op.substr(2, op.length() - 2)));
                stack.push(s);
            }
            else if (op[0] == '3')
            {
                // print
                cout << s[stoi(op.substr(2, op.length() - 2)) - 1] << endl;
            }
            else if (op[0] == '4')
            {
                // undo
                stack.pop();
                s = stack.top();
            }
        }
        
        return 0;
    }
    
  • + 0 comments

    Isn't the expected output of the sample test case wrong?

    Input (stdin): 1 abc, 3 3, 2 3, 1 xy, 3 2, 3 1

    The data contents should be: 1 abc => abc 3 3 => print c 2 3 => deleted abc 1 xy => xy 3 2 => print y 3 1 => print x (not a)

  • + 0 comments
    def TextEditor(ops):
        s=''
        done=[]
        for i in ops:
            if i[0]=='1':
                s=s+(i[1])
                done.append(i)
            elif i[0]=='2':
                e=s[(len(s)-int(i[1])):len(s)]
                s=s[0:(len(s)-int(i[1]))]
                i.append(e)
                done.append(i)
            elif i[0]=='3':
                print(s[int(i[1])-1])
            elif i[0]=='4':
                u=done[-1]
                if u[0]=='1':
                    s=s[0:(len(s)-len(u[1]))]
                elif u[0]=='2':
                    s=s+(u[2])
                done.pop()
        return
        
        
    q=int(input()) 
    ops=[]
    for i in range(q):
        ops.append(input().split())
    TextEditor(ops)