解题思路:
注意事项:
要注意 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 人评分
printf基础练习2 (C语言代码)浏览:306 |
打水问题 (C语言代码)浏览:1098 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:387 |
P1001 (C语言代码)浏览:809 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:1243 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:644 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:674 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:667 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:628 |
星期判断机 (C语言代码)浏览:861 |