SHARE
TWEET

ChangeList

a guest Oct 21st, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.stream.Collectors;
  5.  
  6. public class ChangeList {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         List<Integer> numbers = Arrays.stream(scanner.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
  10.         String input = scanner.nextLine();
  11.         while (!input.equals("end")) {
  12.             String[] command = input.split(" ");
  13.             if (command[0].equals("Delete")) {
  14.                 int element = Integer.parseInt(command[1]);
  15.                 while (numbers.contains(element)) {
  16.                 numbers.remove(Integer.valueOf(element));
  17.                 }
  18.             } else if (command[0].equals("Insert")) {
  19.                 int element = Integer.parseInt(command[1]);
  20.                 int position = Integer.parseInt(command[2]);
  21.                 numbers.add(position, element);
  22.             }
  23.             input = scanner.nextLine();
  24.         }
  25.         for (Integer number : numbers) {
  26.             System.out.print(number + " ");
  27.         }
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top