Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.Scanner;
- public class SaQSimpleTextEditor {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int operationNum = Integer.parseInt(scanner.nextLine());
- ArrayDeque<String> stack = new ArrayDeque<>();
- //String[] task = scanner.nextLine().split("\\s+");
- for (int i = 0; i < operationNum; i++) {
- String[] task = scanner.nextLine().split("\\s+");
- String toDo = task[0];
- if(toDo.equals("1")) {
- String toAppend = task[1];
- if (stack.size()==0) {
- stack.push(toAppend);
- } else {
- toAppend = stack.peek()+toAppend;
- stack.push(toAppend);
- }
- } else if(toDo.equals("2")){
- int toDell = Integer.parseInt(task[1]);
- int toUse = stack.peek().length()-toDell;
- String newStringToPush = "";
- String lastWorkString = stack.peek();
- for (int j = 0; j < toUse; j++) {
- newStringToPush = newStringToPush + lastWorkString.charAt(j);
- }
- stack.push(newStringToPush);
- }else if (toDo.equals("3")) {
- int charNumToPrint = Integer.parseInt(task[1])-1;
- String workWord = stack.peek();
- System.out.println(workWord.charAt(charNumToPrint));
- }else if (toDo.equals("4")) {
- stack.pop();
- }
- //task = scanner.nextLine().split("\\s+");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement