You are viewing a single comment's thread. Return to all comments →
ez in python
class strEditor : def __init__(self): self.setting = [] self.temp = [] def createSetting(self): for s in [input() for _ in range(int(input()))]: main = s.split(" ") code = main[0] command = None if len(main) >1: command = main[1] self.setting.append({"code":code,"command":command}) return self.setting def operationMethod(self,code, command, finalS,idx): if int(code) == 1: self.temp.append(finalS) finalS+=(command) elif int(code) == 2: if 0 <= int(command) <= len(finalS): self.temp.append(finalS) finalS = finalS[:-int(command)] elif int(code) == 3: if 1 <= int(command) <= len(finalS): print(finalS[int(command)-1]) elif int(code) == 4: finalS = self.temp.pop() else: print("Invalid operation code.") return finalS def runCommand(self): finalS = '' for idx in range(len(self.setting)): payloads = self.setting[idx] code = payloads["code"] command = payloads["command"] finalS = self.operationMethod(code, command, finalS,idx) return finalS editor = strEditor() editor.createSetting() editor.runCommand()
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Text Editor
You are viewing a single comment's thread. Return to all comments →
ez in python