Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lekciq;
- import java.util.LinkedHashSet;
- import java.util.Scanner;
- public class ParkingLot {
- public static void main(String[] args) {
- // Create a HashSet to store car numbers
- LinkedHashSet<String> parkingLot = new LinkedHashSet<>();
- // Scanner to read input
- Scanner scanner = new Scanner(System.in);
- // Read input until "END" is encountered
- while (true) {
- String input = scanner.nextLine();
- // Check if input is "END"
- if (input.equals("END")) {
- break;
- }
- // Split input to get direction and car number
- String[] parts = input.split(", ");
- String direction = parts[0];
- String carNumber = parts[1];
- // Process the input
- if (direction.equals("IN")) {
- parkingLot.add(carNumber);
- } else if (direction.equals("OUT")) {
- parkingLot.remove(carNumber);
- }
- }
- // Check if the parking lot is empty and print the result
- if (parkingLot.isEmpty()) {
- System.out.println("Parking Lot is Empty");
- } else {
- // Print all car numbers in the parking lot
- for (String carNumber : parkingLot) {
- System.out.println(carNumber);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement