参考代码:
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 人评分
汽水瓶 (C语言代码)浏览:698 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:377 |
wu-理财计划 (C++代码)浏览:827 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:594 |
简单的a+b (C语言代码)浏览:807 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:460 |
1017题解浏览:588 |
核桃的数量 (C语言代码)浏览:668 |
1024题解浏览:806 |
蓝桥杯历届试题-翻硬币 (C++代码)浏览:872 |