参考代码:
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } for (int i = 0; i < m; i++) { int x = sc.nextInt(),y = sc.nextInt(); if (arr[x-1]!=arr[y-1]){ int a = arr[x-1]; arr[x-1] = arr[y-1]; arr[y-1] = a; } } for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }
0.0分
1 人评分