Advertisement
Hey_Donny

Students Row

May 30th, 2022
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.LinkedList;
  3. import java.util.Scanner;
  4.  
  5. public class StudentsRow {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String[] stringArray = scanner.nextLine().split(" ");
  10. int N = Integer.parseInt(stringArray[0]);
  11. int k = Integer.parseInt(stringArray[1]);
  12.  
  13. String[] arrayOne = scanner.nextLine().split(" ");
  14.  
  15. LinkedList<String> names = new LinkedList<>(Arrays.asList(arrayOne).subList(0, N));
  16.  
  17. for (int i = 0; i < k; i++) {
  18. String[] arrayTwo = scanner.nextLine().split(" ");
  19. names.remove(arrayTwo[0]);
  20. int newIndex = names.indexOf(arrayTwo[1]);
  21. names.add(newIndex, arrayTwo[0]);
  22. }
  23.  
  24. for (int i = 0; i < N; i++) {
  25. if ((i == N - 1)) {
  26. System.out.print(names.get(i));
  27. } else {
  28. System.out.print(names.get(i) + " ");
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement