You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String outputString = ""; Stack<String> stack = new Stack<>(); stack.push(outputString); List<Character> result = new ArrayList<>(); for (int i = 0; i < n; i++) { String append = null; int show = 0; int del = 0; String inp = br.readLine(); String arr[] = inp.split(" "); int opt = Integer.parseInt(arr[0]); switch (opt) { case 1: append = arr[1]; outputString += append; stack.push(outputString); break; case 2: del = Integer.parseInt(arr[1]); outputString = outputString.substring(0, outputString.length() - del); stack.push(outputString); break; case 3: show = Integer.parseInt(arr[1]); result.add(outputString.charAt(show - 1)); break; case 4: stack.pop(); outputString = stack.peek(); } } try { for(Character j:result) System.out.println(j); } catch (Exception e) { } }
}
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 →
import java.io.; import java.util.;
public class Solution {
}