Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.LinkedList;
- import java.util.Scanner;
- public class StudentsRow {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] stringArray = scanner.nextLine().split(" ");
- int N = Integer.parseInt(stringArray[0]);
- int k = Integer.parseInt(stringArray[1]);
- String[] arrayOne = scanner.nextLine().split(" ");
- LinkedList<String> names = new LinkedList<>(Arrays.asList(arrayOne).subList(0, N));
- for (int i = 0; i < k; i++) {
- String[] arrayTwo = scanner.nextLine().split(" ");
- names.remove(arrayTwo[0]);
- int newIndex = names.indexOf(arrayTwo[1]);
- names.add(newIndex, arrayTwo[0]);
- }
- for (int i = 0; i < N; i++) {
- if ((i == N - 1)) {
- System.out.print(names.get(i));
- } else {
- System.out.print(names.get(i) + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement