SHARE
TWEET

Untitled

a guest Jun 20th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         List<String> names = new ArrayList<>();
  10.  
  11.         for (int i = 0; i < n; i++) {
  12.             String[] tokens = scanner.nextLine().split("\\s+");
  13.  
  14.             if (tokens.length == 3) {
  15.                 if (!names.contains(tokens[0])) {
  16.                     names.add(tokens[0]);
  17.                 } else {
  18.                     System.out.println(String.format("%s is already in the list!", tokens[0]));
  19.                 }
  20.             } else if (tokens.length == 4) {
  21.                 if (!names.contains(tokens[0])) {
  22.                     System.out.println(String.format("%s is not in the list!", tokens[0]));
  23.                 }
  24.                 names.remove(tokens[0]);
  25.             }
  26.         }
  27.  
  28.         names.forEach(System.out::println);
  29.     }
  30. }
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