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.
publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerinput=newScanner(System.in);intq=input.nextInt();Stack<String>stack=newStack<>();StringBuildersb=newStringBuilder();for(intj=0;j<q;j++){intchoose=input.nextInt();switch(choose){case1:stack.push(sb.toString());StringnewText=input.next();sb.append(newText);break;case2:stack.push(sb.toString());intk=input.nextInt();sb.delete(sb.length()-k,sb.length());break;case3:intkth=input.nextInt();System.out.println(sb.charAt(kth-1));break;case4:sb.setLength(0);sb.append(stack.pop());break;}}}
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 →
java 8