小孙


私信TA

用户名:2409244461

访问量:8534

签 名:

这是一个废物

等  级
排  名 292
经  验 5484
参赛次数 1
文章发表 40
年  龄 19
在职情况 学生
学  校 河南工业职业技术学院
专  业 软件技术

  自我简介:


参考代码:

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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区