解题思路:二维数组+冒泡排序注意事项:数组界限,不要越界 参考代码: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt();//一共要录入几个人的成绩 String[][] item = new String[n][2];//接收n个人的成绩和姓名 for (int i = 0; i < item.length; i++) { for (int j = 0; j < 2; j++) { item[i][j] = scanner.next(); } } for (int i = 0; i < item.length-1; i++) {//循环排序 for (int j = 0; j < item.length-1-i; j++) { if (Integer.parseInt(item[j][1])<Integer.parseInt(item[j+1][1]))//成绩相等 { String[] temp = item[j]; item[j] = item[j+1]; item[j+1] = temp; }else if (Integer.parseInt(item[j][1])==Integer.parseInt(item[j+1][1])) { int k =0; while (item[j][0].charAt(k)==item[j+1][0].charAt(k)) {//对比名字的字典序 k++; if (item[j][0].length()==k) { k--; break; } } if (item[j][0].charAt(k)>item[j+1][0].charAt(k)) { String[] temp = item[j]; item[j] = item[j+1]; item[j+1] = temp; } } } } for (int i = 0; i < item.length; i++) { System.out.println(item[i][0]); } } }
0.0分
1 人评分
【出圈】 (C语言代码)浏览:794 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:654 |
printf基础练习2 (C语言代码)浏览:741 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:590 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:574 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:505 |
WU-蓝桥杯算法提高VIP-企业奖金发放 (C++代码)浏览:1163 |
1642题解浏览:711 |
printf基础练习2 (C语言代码)浏览:503 |
Tom数 (C语言代码)浏览:552 |