Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class _03_Task {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> list = Arrays.stream(scanner.nextLine().split(" "))
- .map(Integer::parseInt).collect(Collectors.toList());
- String input = scanner.nextLine();
- while (!input.equals("END")) {
- String[] line = input.split(" ");
- switch (line[0]) {
- case "Change":
- int ind1 = list.indexOf(Integer.parseInt(line[1]));
- int num = Integer.parseInt(line[2]);
- if (ind1 != -1) {
- list.set(ind1, num);
- }
- break;
- case "Hide":
- num = Integer.parseInt(line[1]);
- int index = list.indexOf(num);
- if (index != -1) {
- list.remove(index);
- }
- break;
- case "Switch":
- int index1 = list.indexOf(Integer.parseInt(line[1]));
- int ind2 = list.indexOf(Integer.parseInt(line[2]));
- int firstInt = Integer.parseInt(line[1]);
- int secondInt = Integer.parseInt(line[2]);
- if (index1 != -1 && ind2 != -1) {
- list.set(index1, secondInt);
- list.set(ind2, firstInt);
- }
- break;
- case "Insert":
- int number = Integer.parseInt(line[2]);
- int indexIns = Integer.parseInt(line[1]) + 1;
- if (indexIns >= 0 && indexIns <= list.size()) {
- list.add(indexIns, number);
- }
- break;
- case "Reverse":
- Collections.reverse(list);
- break;
- }
- input = scanner.nextLine();
- }
- for (Integer integer : list) {
- System.out.print(integer + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement