LintCode 846.多关键字排序

描述

给定 n 个学生的学号(从 1n 编号)以及他们的考试成绩,表示为(学号,考试成绩),请将这些学生按考试成绩降序排序,若考试成绩相同,则按学号升序排序。

答案

public class Solution {
/**
* @param array: the input array
* @return: the sorted array
*/
public int[][] multiSort(int[][] array) {
// Write your code here
for(int i = 0; i < array.length-1; i++) {
for(int j = i+1; j < array.length; j++) {
int[] temp = array[i];
if(array[i][1] < array[j][1]) {
array[i] = array[j];
array[j] = temp;
} else if (array[i][1] == array[j][1]) {
if(array[i][0] > array[j][0]) {
array[i] = array[j];
array[j] = temp;
}
}
}
}
return array;
}
}

总结

冒泡排序

LintCode 846.多关键字排序的更多相关文章

  1. 排序技巧——双关键字排序(快速排序,sort)

    一个萌新的成长之路 Background 在做题过程中,我们常会遇到对双关键字排序的情况,如:当分数相等时,序号小的在前. 这时我们可以通过定义cmp函数作为sort的参数进行排序. Solution ...

  2. SQL 按关键字排序

    SQL ORDER BY Keyword(按关键字排序) ORDER BY 关键字用于对结果集进行排序. SQL ORDER BY 关键字 ORDER BY 关键字用于按升序或降序对结果集进行排序. ...

  3. Python关键字排序

    一.当排序关键字多于1个时,我们使用lambda表达式来描述关键字key arr=[(1,4,3),(1,3,3),(2,1,4),(3,5,1)] arr.sort(key=lambda s:(s[ ...

  4. STL函数库的应用第二弹——快排sort函数与结构体关键字排序

    时隔20多天,本蒟蒻终于记起了他的博客园密码!!! 废话不多说,今天主题:STL快排函数sort()与结构体关键字排序 Part 1:引入和导语 首先,我们需要知道,algorithm库里有一些奇怪的 ...

  5. SRM 207 Div II Level Two: RegularSeason,字符串操作(sstream),多关键字排序(操作符重载)

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=2866&rd=5853 主要是要对字符串的操作要熟悉,熟 ...

  6. c++结构体双关键字排序

    #include<bits/stdc++.h> using namespace std; struct node{ int l,r; }num[]; int w_comp(const no ...

  7. MongoDB-查询关键字/排序等

    查询关键字 并列查询$and # 条件都成立才可以查询到结果 db.stutent.find({$and:[{name:"小漩涡"},{age:30}]}) 或查询$or # 有一 ...

  8. [LintCode] Sort Integers 整数排序

    Given an integer array, sort it in ascending order. Use selection sort, bubble sort, insertion sort ...

  9. lintcode :搜索旋转排序数组

    题目 搜索旋转排序数组 假设有一个排序的按未知的旋转轴旋转的数组(比如,0 1 2 4 5 6 7 可能成为4 5 6 7 0 1 2).给定一个目标值进行搜索,如果在数组中找到目标值返回数组中的索引 ...

随机推荐

  1. springcloud学习第一坑

    我是根据周立先生所写的<Spring+Cloud与Docker微服务架构实战>来学习SpringCloud的,我会记录下来我日常遇到的所有问题,包括但不仅只包括SpringCloud的问题 ...

  2. Java学习-051-Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError

    错误信息:Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting St ...

  3. webservice学习教程(一):理论

    一. WebService到底是什么? webservice是一种跨平台,跨语言的规范,用于不同平台,不同语言开发的应用之间的交互 WebService是一个SOA(面向服务的编程)的架构,它是不依赖 ...

  4. 【Solution】idea中dtd没有找到

    问题: idea中dtd没有找到 解决: 一般是相关依赖没有加进来,把相关依赖添加进来即可 在pom中添加依赖

  5. idea没配置Tomcat容器报错及解决方法

    servlet报错,提示没有一个容器,需要一个容器来运行,说明没有tomcat容器. 看看idea的配置有没有配置tomcat? 果然没有配置tomcat容器(正常画红框的地方会出现配置的tomcat ...

  6. TextField widgets require a Material widget ancestor

    TextField widget需要被包裹在Scaffold widget中,否则会报错

  7. SQL的优化整理

    1,对查询进行优化,要尽量避免全表扫描,首先应考虑在进行条件判断的字段上创建索引 (注意:如果一张数据表中的数据更新频率太高,更新数据之后需要重新创索引,这个过程很耗费性能,所以更新频率高的数据表慎用 ...

  8. The Non-Inverting Amplifier Output Resistance by Adrian S. Nastase [转载]

    Source Address: http://masteringelectronicsdesign.com/the-non-inverting-amplifier-output-resistance/ ...

  9. Windbg程序调试系列5-高CPU问题分析

    上篇博客中给大家分享了使用Windbg进行Live Debugging: Windbg程序调试系列4-Live Debugging 本篇中我们继续,跟大家分享常见的应用程序高CPU使用率问题分析. 先 ...

  10. WPF 查找控件的所有子控件

    /// <summary> /// 查找子控件 /// </summary> /// <typeparam name="T">控件类型</ ...