We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
staticvoidMain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */intq=int.Parse(Console.ReadLine().Trim());Editoreditor=newEditor();for(inti=0;i<q;i++){string[]op=Console.ReadLine().Trim().Split(' ');editor.Execute(int.Parse(op[0]),op.Length>1?op[1]:null);}}publicclassEditor{publicstringText=string.Empty;publicStack<string>Undos=newStack<string>();privateITextOperation[]operations={newAppendOperation(),newDeleteOperation(),newPrintOperation(),newUndoOperation()};publicvoidExecute(intopId,stringp){operations[opId-1].Execute(this,p);}}publicinterfaceITextOperation{publicvoidExecute(Editoreditor,stringval);}publicclassAppendOperation:ITextOperation{publicvoidExecute(Editoreditor,stringval){editor.Undos.Push(editor.Text);editor.Text+=val;}}publicclassDeleteOperation:ITextOperation{publicvoidExecute(Editoreditor,stringval){intk=int.Parse(val);editor.Undos.Push(editor.Text);editor.Text=editor.Text.Remove(editor.Text.Length-k);}}publicclassPrintOperation:ITextOperation{publicvoidExecute(Editoreditor,stringval){intk=int.Parse(val);Console.WriteLine(editor.Text[k-1]);}}publicclassUndoOperation:ITextOperation{publicvoidExecute(Editoreditor,stringval){editor.Text=editor.Undos.Pop();}}
Cookie support is required to access HackerRank
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 →