Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- /**
- * Created by soki on 20-May-16.
- */
- public class CalculateSequenceWithQueue {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String text = "";
- int numInputLines = scanner.nextInt();
- int countToErase;
- int indexToReturn;
- byte lastOperationType ;
- for (int i = 0; i < numInputLines; i++) {
- String[] command = scanner.nextLine().split(" ");
- switch (command[0]) {
- case "1":
- text.concat(command[1]);
- break;
- case "2":
- countToErase = Integer.parseInt(command[1]);
- text = text.substring(0,text.length() - countToErase);
- break;
- case "3":
- indexToReturn = Integer.parseInt(command[1]);
- System.out.println(text.charAt(indexToReturn - 1));
- break;
- //case 4 - undoes last case 1 or 2 operation
- case "4":
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement