大三菜鸡开始蓝桥杯的刷题之路

[蓝桥杯]交换

大三菜鸡开始蓝桥杯的刷题之路_第1张图片Easy

`import java.util.Scanner;
public class Main {
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a=scanner.nextInt();
    int b=scanner.nextInt();
    int[] x=new int[a];
    for (int i = 0; i <a ; i++) {
        x[i]=scanner.nextInt();
    }
    for (int i = 0; i <b ; i++) {
      int f=scanner.nextInt();
      int t=scanner.nextInt();
      int temp=0;
      temp=x[f-1];
      x[f-1]=x[t-1];
      x[t-1]=temp;
    }
    System.out.println();
    for (int i = 0; i <x.length ; i++) {
        System.out.println(x[i]);
    }
}
}
`

你可能感兴趣的:(大三菜鸡开始蓝桥杯的刷题之路)