You are viewing a single comment's thread. Return to all comments →
It works fine, but I'm getting timeout in tests 8, 9, 10
public static void main(String[] args) { Scanner s = new Scanner(System.in); Stack<String> history = new Stack<>(); StringBuilder current = new StringBuilder(); int count = s.nextInt(); for (int i = 0; i < count; i++) { int operation = s.nextInt(); switch (operation) { case 1: history.push(current.toString()); current.append(s.next()); break; case 2: history.push(current.toString()); current = new StringBuilder(current.substring(0, current.length() - s.nextInt())); break; case 3: System.out.println(current.charAt(s.nextInt() - 1)); break; case 4: current = new StringBuilder(history.pop()); break; } } }
How can I make it better?
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 →
It works fine, but I'm getting timeout in tests 8, 9, 10
How can I make it better?