Advertisement
Ligh7_of_H3av3n

02. SoftUni Party

May 20th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package Lekciq;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Scanner;
  5. import java.util.Set;
  6. import java.util.TreeSet;
  7.  
  8. public class SoftUniParty {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.  
  13.         // Sets for VIP and regular guests
  14.         Set<String> vipGuests = new HashSet<>();
  15.         Set<String> regularGuests = new HashSet<>();
  16.  
  17.  
  18.         // Reading reservation numbers until "PARTY"
  19.         String input = scanner.nextLine();
  20.         while (!input.equals("PARTY")) {
  21.             if (Character.isDigit(input.charAt(0))) {
  22.                 vipGuests.add(input);
  23.             } else {
  24.                 regularGuests.add(input);
  25.             }
  26.             input = scanner.nextLine();
  27.         }
  28.  
  29.         // Reading arrival of guests until "END"
  30.         input = scanner.nextLine();
  31.         while (!input.equals("END")) {
  32.             vipGuests.remove(input);
  33.             regularGuests.remove(input);
  34.             input = scanner.nextLine();
  35.         }
  36.  
  37.         // Output the guests who didn't come
  38.         int totalNoShows = vipGuests.size() + regularGuests.size();
  39.         System.out.println(totalNoShows);
  40.  
  41.         // VIP guests first
  42.         TreeSet<String> sortedVipGuests = new TreeSet<>(vipGuests);
  43.         TreeSet<String> sortedRegularGuests = new TreeSet<>(regularGuests);
  44.  
  45.         sortedVipGuests.forEach(System.out::println);
  46.         sortedRegularGuests.forEach(System.out::println);
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement