Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Uprajnenie;
- import java.util.Scanner;
- import java.util.Set;
- import java.util.TreeSet;
- public class PeriodicTable {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // Read the number of compounds
- int n = scanner.nextInt();
- scanner.nextLine(); // Consume the newline character
- Set<String> uniqueElements = new TreeSet<>();
- // Read each compound and add elements to the set
- for (int i = 0; i < n; i++) {
- String compound = scanner.nextLine();
- String[] elements = compound.split("\\s+");
- for (String element : elements) {
- uniqueElements.add(element);
- }
- }
- // Print the unique elements in ascending order
- for (String element : uniqueElements) {
- System.out.print(element + " ");
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement