Sort by

recency

|

544 Discussions

|

  • + 0 comments

    typescript boilerplate: 'use strict';

    process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString: string = ''; let inputLines: string[] = []; let currentLine: number = 0; process.stdin.on('data', function(inputStdin: string): void { inputString += inputStdin; });

    process.stdin.on('end', function(): void { inputLines = inputString.split('\n'); inputString = ''; main(); });

    function readLine(): string { return inputLines[currentLine++]; }

    class TextEditor { private currentText:string; // Enter your code here constructor(){ this.currentText ="" } append(w:string){ // Enter your code here } delete(k:number){ // Enter your code here } print(k:number){ // Enter your code here } undo(){ // Enter your code here } }

    type EditorMethod = "append" | "delete" | "print" | "undo";

    function main() { const commandMap = {"1": "append", "2": "delete", "3" : "print", "4": "undo" } as const;

    const textEditor = new TextEditor();
    inputLines.shift()
    inputLines.map((inputLine:string) => {
        const [command, input] = inputLine.split(" ") as ["1"|"2"|"3"|"4", string]
        const method = commandMap[command] 
        if (method == "undo") return textEditor.undo()
        if (method == "append") return textEditor.append(input);
    
        return textEditor[method](Number(input))
    } );
    

    }

  • + 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)