SHARE
TWEET

Untitled

a guest Feb 21st, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6.  
  7. public class HouseParty {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         ArrayList<String> guestsList = new ArrayList<>();
  11.         int n = Integer.parseInt(scanner.nextLine());
  12.  
  13.         for (int i = 0; i < n; i++) {
  14.             String[] tokens = scanner.nextLine().split("\\s+", 2);
  15.             String name = tokens[0];
  16.             if (tokens[1].equals("is going!")) {
  17.                 if (guestsList.contains(name)) {
  18.                     System.out.printf("%s is already in the list!%n", name);
  19.                 } else {
  20.                     guestsList.add(name);
  21.                 }
  22.  
  23.             } else {
  24.                 if (guestsList.contains(name)) {
  25.                     guestsList.remove(name);
  26.                 } else {
  27.                     System.out.printf("%s is not in the list!%n", name);
  28.                 }
  29.             }
  30.         }
  31.  
  32.         for (String name : guestsList) {
  33.             System.out.println(name);
  34.         }
  35.     }
  36. }
  37. //input:
  38. //4
  39. //Allie is going!
  40. //George is going!
  41. //John is not going!
  42. //George is not going!
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