Simple Text Editor

Sort by

recency

|

63 Discussions

|

  • + 0 comments

    Fullname = input() Nickname = input() Age = input() Zodiacsign = input() Weight = input() Height = input() Color = input() Song = input() Movie = input() Hobby = input()

    print(f"Hi! My name is {Fullname} and my friends call me {Nickname}. I'm {Age} years old and my zodiac sign is {Zodiacsign}. I currently weigh {Weight} kg and am {Height} cm tall.\n\nOut of all the colors, I tend to favor {Color} the most. {Song} is one song I currently like and the first movie to come to mind is {Movie}. Lastly, one of my hobbies is {Hobby}. That's all :)")

  • + 0 comments
    n_q=int(input())
    undo_stack=[]
    s=""
    
    def perform(op, param, in_undo=False):
        global s
        match op:
            case 'append':
                if not in_undo:
                    undo_stack.append(('delete', len(param)))
                s+= param
            case 'delete':
                if not in_undo:
                     undo_stack.append(('append', s[len(s)-int(param):])) 
                s = s[0:len(s)-int(param)]
            case 'print':
                print(s[int(param)-1])
            case 'undo':
                un_op, un_param = undo_stack.pop()
                perform(un_op, un_param, in_undo=True)
    
                
    ops=['ops','append','delete','print','undo']  
    for _ in range(n_q):
        q=input().split()
        op=ops[int(q[0])]
        param = None
        if op!='undo':
            param=q[1]
        #now, perform
        perform(op, param)
        
    
  • + 0 comments

    Python 3:

    q = int(input())
    
    s = ''
    revert = [s]
    
    for _ in range(q):
        line = input().strip().split()
        operation = int(line[0])
        try:
            argument = line[1]
        except Exception:
            pass
            
        match operation:
            case 1:
                revert.append(s)
                s += argument
            case 2:
                revert.append(s)
                for _ in range(int(argument)):
                    s = s[:-1]
            case 3:
                print(s[int(argument)-1])
            case 4:
                s = revert.pop()
    
  • + 0 comments

    On the one hand

    The editor initially contains an empty string, .

    On the other hand, Why does your example start with inital value of S?!

    wtf

  • + 0 comments

    JavaScript Solution:-

    function processData(input) {
        let currentString = '';
        let operationHistory = [];
        const operations = input.split('\n').slice(1); 
        for (let op of operations) {
            const opArr = op.split(' ');
            const type = parseInt(opArr[0]);
            if (type === 1) { 
                const strToAppend = opArr[1];
                currentString += strToAppend;
                operationHistory.push({ type: 1, value: strToAppend }); 
            } else if (type === 2) { // Delete operation
                const numToDelete = parseInt(opArr[1]);
                const deletedString = currentString.slice(-numToDelete); 
                currentString = currentString.slice(0, -numToDelete); 
                operationHistory.push({ type: 2, value: deletedString }); 
            } else if (type === 3) { // Print operation
                const index = parseInt(opArr[1]) - 1; 
                console.log(currentString[index]);
    
            } else if (type === 4) { 
                const lastOperation = operationHistory.pop();
                if (lastOperation.type === 1) { // Undo append
                    const appendedString = lastOperation.value;
                    currentString = currentString.slice(0, -appendedString.length); 
                } else if (lastOperation.type === 2) { // Undo delete
                    const deletedString = lastOperation.value;
                    currentString += deletedString;
                }
            }
        }
    }