SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.*; | |
| 2 | import java.util.stream.Collectors; | |
| 3 | ||
| 4 | public class demo {
| |
| 5 | public static void main(String[] args) {
| |
| 6 | Scanner scanner = new Scanner(System.in); | |
| 7 | //[3,4,5,6] | |
| 8 | List<Integer> numbers = Arrays.stream(scanner.nextLine().split("\\s+"))
| |
| 9 | .map(Integer::parseInt).collect(Collectors.toList()); | |
| 10 | ||
| 11 | String input = scanner.nextLine(); | |
| 12 | ||
| 13 | while (!input.equals("end")) {
| |
| 14 | //"Delete {element}" -> split -> ["Delete", "5"]
| |
| 15 | //"Insert {element} {position}" -> ["Insert", "5", "3"]
| |
| 16 | String command = input.split("\\s+")[0]; //Delete или Insert
| |
| 17 | int element = Integer.parseInt(input.split("\\s+")[1]);
| |
| 18 | ||
| 19 | if (command.equals("Delete")) {
| |
| 20 | numbers.removeAll(Arrays.asList(element)); | |
| 21 | } else if (command.equals("Insert")) {
| |
| 22 | int index = Integer.parseInt(input.split("\\s+")[2]);
| |
| 23 | numbers.add(index, element); | |
| 24 | } | |
| 25 | input = scanner.nextLine(); | |
| 26 | } | |
| 27 | ||
| 28 | printList(numbers); | |
| 29 | } | |
| 30 | ||
| 31 | private static void printList(List<Integer> numbers) {
| |
| 32 | for (int number : numbers) {
| |
| 33 | System.out.print(number + " "); | |
| 34 | } | |
| 35 | } | |
| 36 | } |