package question;import java.util.Arrays;import java.util.Comparator;/*@author: Roderland@create: 2020年09月21日---21:57*/public class Question406 {public static void main(String[] args) {//[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]int[][] people = new int[][]{{7, 0}, {4, 4}, {7, 1}, {5, 0}, {6, 1}, {5, 2}};new Question406().reconstructQueue(people);}public int[][] reconstructQueue(int[][] people) {Arrays.sort(people, new Comparator<int[]>() {@Overridepublic int compare(int[] o1, int[] o2) {if (o1[0] < o2[0]) return 1;else if (o1[0] > o2[0]) return -1;else return o1[1] - o2[1];}});for (int[] person : people) {System.out.println(person[0] + " " + person[1]);}for (int i = 0; i < people.length; i++) {if (people[i][1] != i) {int[] tmp = people[i];for (int j = i; j > tmp[1]; j--) {people[j] = people[j - 1];}people[tmp[1]] = tmp;}}System.out.println("=========================");for (int[] person : people) {System.out.println(person[0] + " " + person[1]);}return people;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。