Advertisement
IrinaIgnatova

Parking Lot-Set

Oct 23rd, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.io.IOException;
  5.  
  6.  
  7. import java.time.LocalTime;
  8. import java.time.format.DateTimeFormatter;
  9. import java.util.*;
  10.  
  11. public class Main {
  12.  
  13.  
  14.     public static void main(String[] args) {
  15.         Scanner scanner = new Scanner(System.in);
  16.  
  17.         String line = scanner.nextLine();
  18.         HashSet<String> parkingLot = new HashSet<>();
  19.  
  20.         while (!line.equals("END")) {
  21.             String[] parts = line.split(", ");
  22.  
  23.             if (parts[0].equals("IN")) {
  24.                 parkingLot.add(parts[1]);
  25.             } else {
  26.                 parkingLot.remove(parts[1]);
  27.             }
  28.  
  29.             line = scanner.nextLine();
  30.         }
  31.  
  32.         if (parkingLot.isEmpty()) {
  33.             System.out.println("Parking Lot is Empty");
  34.         } else {
  35.             for (String carNumber : parkingLot) {
  36.                 System.out.println(carNumber);
  37.  
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement