SHARE
TWEET

Untitled

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