解题思路:
注意事项:
要注意 int m = scanner.nextInt();
scanner.nextLine();要加一个空的,否则会自动跳过String s的读取
String s = scanner.nextLine();
参考代码:
public class 交换easy {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
scanner.nextLine();
String s = scanner.nextLine();
String[] split = s.trim().split("\\s");
for (int x1=0;x1<m;x1++) {
int x = scanner.nextInt() - 1;
int y = scanner.nextInt() - 1;
String t = split[x];
split[x] = split[y];
split[y] = t;
}
for (int i = 0; i <n; i++) {
System.out.println(split[i]);
}
}
}
0.0分
1 人评分
【亲和数】 (C语言代码)浏览:559 |
C语言程序设计教程(第三版)课后习题9.1 (Java代码)浏览:473 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:560 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:666 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:894 |
WU-整除问题 (C++代码)浏览:616 |
用筛法求之N内的素数。 (C语言代码)浏览:870 |
母牛的故事 (C语言代码)浏览:1432 |
printf基础练习2 (C语言代码)浏览:527 |
Hello, world! (C语言代码)浏览:858 |