解题思路:java中没有指针链表的概念,所以可以用二维数组来解决,用来存储学号和成绩,我的排序过程有可能有点麻烦,希望看题解的人能给出建议
注意事项:
参考代码:
import java.util.Scanner;
public class xunlian1052 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int a[][] = new int[n][2];
int b[][] = new int[m][2];
int c[][] = new int[m + n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
a[i][j] = sc.nextInt();
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 2; j++) {
b[i][j] = sc.nextInt();
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
c[i][j] = a[i][j];
}
}
for (int i = n; i < m + n; i++) {
for (int j = 0; j < 2; j++) {
c[i][j] = b[i - n][j];
}
}
for (int i = 0; i < c.length; i++) {
for (int j = i + 1; j < c.length; j++) {
if (c[i][0] > c[j][0]) {
int t = c[i][0];
c[i][0] = c[j][0];
c[j][0] = t;
int t1 = c[i][1];
c[i][1] = c[j][1];
c[j][1] = t1;
}
}
}
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[i].length; j++) {
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}
}
0.0分
0 人评分