Advertisement
Ligh7_of_H3av3n

01. Unique Usernames

May 21st, 2024
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package Uprajnenie;
  2.  
  3. import java.util.LinkedHashSet;
  4. import java.util.Scanner;
  5. import java.util.Set;
  6.  
  7. public class UniqueUsernames {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.  
  12.         // Read the number of usernames as a string and convert to integer
  13.         int n = Integer.parseInt(scanner.nextLine().trim());
  14.  
  15.         Set<String> uniqueUsernames = new LinkedHashSet<>();
  16.  
  17.         // Read usernames and add them to the set
  18.         for (int i = 0; i < n; i++) {
  19.             String username = scanner.nextLine().trim();
  20.             uniqueUsernames.add(username);
  21.         }
  22.  
  23.         // Print the unique usernames in the order of insertion
  24.         for (String username : uniqueUsernames) {
  25.             System.out.println(username);
  26.         }
  27.  
  28.         scanner.close();
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement