Advertisement
damesova

House Party

Feb 20th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class _03_HouseParty {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.  
  11.         List<String> listParty = new ArrayList<>();
  12.  
  13.         for (int i = 0; i < n; i++) {
  14.             String input = scanner.nextLine();
  15.             String[] data = input.split("\\s+");
  16.             String name = data[0];
  17.             String goingOrNot = data[2];
  18.  
  19.             if (data.length == 4){
  20.  
  21.                 if (listParty.contains(name)){
  22.                     listParty.remove(name);
  23.                 } else {
  24.                     System.out.println(data[0] + " is not in the list!");
  25.                 }
  26.  
  27.             } else {
  28.                 if (!listParty.contains(name)){
  29.                     listParty.add(name);
  30.                 } else {
  31.                     System.out.println(data[0] + " is already in the list!");
  32.                 }
  33.             }
  34.        
  35.         for (String name : listParty) {
  36.             System.out.println(name);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement