Advertisement
Ligh7_of_H3av3n

01. Parking Lot

May 20th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package Lekciq;
  2.  
  3. import java.util.LinkedHashSet;
  4. import java.util.Scanner;
  5.  
  6. public class ParkingLot {
  7.     public static void main(String[] args) {
  8.         // Create a HashSet to store car numbers
  9.         LinkedHashSet<String> parkingLot = new LinkedHashSet<>();
  10.  
  11.         // Scanner to read input
  12.         Scanner scanner = new Scanner(System.in);
  13.  
  14.         // Read input until "END" is encountered
  15.         while (true) {
  16.             String input = scanner.nextLine();
  17.  
  18.             // Check if input is "END"
  19.             if (input.equals("END")) {
  20.                 break;
  21.             }
  22.  
  23.             // Split input to get direction and car number
  24.             String[] parts = input.split(", ");
  25.             String direction = parts[0];
  26.             String carNumber = parts[1];
  27.  
  28.             // Process the input
  29.             if (direction.equals("IN")) {
  30.                 parkingLot.add(carNumber);
  31.             } else if (direction.equals("OUT")) {
  32.                 parkingLot.remove(carNumber);
  33.             }
  34.         }
  35.  
  36.         // Check if the parking lot is empty and print the result
  37.         if (parkingLot.isEmpty()) {
  38.             System.out.println("Parking Lot is Empty");
  39.         } else {
  40.             // Print all car numbers in the parking lot
  41.             for (String carNumber : parkingLot) {
  42.                 System.out.println(carNumber);
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement