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.
classSolution{privateenumOperation{Append,Delete}staticvoidMain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */varnumberOfInputs=Int32.Parse(Console.ReadLine()!);vartheString=string.Empty;varoperations=newStack<(Operation,string)>();for(var_=0;_<numberOfInputs;_++){varoperation=Console.ReadLine()!.Split();switch(operation[0]){case"1":theString+=operation[1];operations.Push(new(Operation.Append,operation[1]));continue;case"2":vark=Int32.Parse(operation[1]);varstringToRemove=theString[(theString.Length-k)..];theString=theString.Substring(0,theString.Length-k);operations.Push(new(Operation.Delete,stringToRemove));continue;case"3":k=Int32.Parse(operation[1]);Console.WriteLine(theString[k-1]);continue;case"4":vartheOperation=operations.Pop();if(theOperation.Item1==Operation.Append){theString=theString.Substring(0,theString.Length-theOperation.Item2.Length);continue;}theString+=theOperation.Item2;continue;}}}}
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 →
My C# solution