You are viewing a single comment's thread. Return to all comments →
Java
try(Scanner scan = new Scanner(System.in)){ int n = scan.nextInt(); scan.nextLine(); Stack<String> history = new Stack<>(); String text="" ; for (int i = 0; i < n; i++) { int command = scan.nextInt(); switch(command){ case 1: history.push(text); text+=scan.nextLine().trim(); break; case 2: history.push(text); text = text.substring(0, text.length()-scan.nextInt()); break; case 3: System.out.println(text.charAt(scan.nextInt()-1)); break; case 4: text= history.pop(); break; } } }
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