LintCode 846.多关键字排序
LintCode 846.多关键字排序
描述
给定 n
个学生的学号(从 1
到 n
编号)以及他们的考试成绩,表示为(学号,考试成绩),请将这些学生按考试成绩降序排序,若考试成绩相同,则按学号升序排序。
答案
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.多关键字排序的更多相关文章
- 排序技巧——双关键字排序(快速排序,sort)
一个萌新的成长之路 Background 在做题过程中,我们常会遇到对双关键字排序的情况,如:当分数相等时,序号小的在前. 这时我们可以通过定义cmp函数作为sort的参数进行排序. Solution ...
- SQL 按关键字排序
SQL ORDER BY Keyword(按关键字排序) ORDER BY 关键字用于对结果集进行排序. SQL ORDER BY 关键字 ORDER BY 关键字用于按升序或降序对结果集进行排序. ...
- Python关键字排序
一.当排序关键字多于1个时,我们使用lambda表达式来描述关键字key arr=[(1,4,3),(1,3,3),(2,1,4),(3,5,1)] arr.sort(key=lambda s:(s[ ...
- STL函数库的应用第二弹——快排sort函数与结构体关键字排序
时隔20多天,本蒟蒻终于记起了他的博客园密码!!! 废话不多说,今天主题:STL快排函数sort()与结构体关键字排序 Part 1:引入和导语 首先,我们需要知道,algorithm库里有一些奇怪的 ...
- SRM 207 Div II Level Two: RegularSeason,字符串操作(sstream),多关键字排序(操作符重载)
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=2866&rd=5853 主要是要对字符串的操作要熟悉,熟 ...
- c++结构体双关键字排序
#include<bits/stdc++.h> using namespace std; struct node{ int l,r; }num[]; int w_comp(const no ...
- MongoDB-查询关键字/排序等
查询关键字 并列查询$and # 条件都成立才可以查询到结果 db.stutent.find({$and:[{name:"小漩涡"},{age:30}]}) 或查询$or # 有一 ...
- [LintCode] Sort Integers 整数排序
Given an integer array, sort it in ascending order. Use selection sort, bubble sort, insertion sort ...
- lintcode :搜索旋转排序数组
题目 搜索旋转排序数组 假设有一个排序的按未知的旋转轴旋转的数组(比如,0 1 2 4 5 6 7 可能成为4 5 6 7 0 1 2).给定一个目标值进行搜索,如果在数组中找到目标值返回数组中的索引 ...
随机推荐
- Django中cookie和session使用
cookie和session的简单使用 def cookie(request): """ 操作cookie """ resp = HttpR ...
- .Net开发常用工具插件
多功能工具 Notepad++/Sublime Text 3/VS code Web请求工具 Postman .Net开发工具 Microsoft Visual Studio以及代码规范审查插件Sty ...
- python 循环 while
count = 1while count <= 5: print("大家好!") count = count + 1 结果:while 可以进行循环, count 表示计数, ...
- No input file specified. phpStudy nginx报错解决方案
1.首先观察路径是否存在, 2.在vhsos.conf文件中 先科普下: 在Windows系统中,正斜杠 / 表示除法,用来进行整除运算:反斜杠 \ 用来表示目录. 在Unix系统中,/ 表示目录:\ ...
- 002-MVC布局页
~/Views/Shared/_LayoutPage1.cshtml <!DOCTYPE html> <html> <head> <meta name=&qu ...
- SV-assertion
断言(assert)是一种描述性语言,通过描述的期望结果来进行仿真验证. 断言有一个更加基础的信息,我们称为属性(property),属性可以作为断言结果,功能覆盖点,形式检查和约束随机激励生成. 断 ...
- SQL死锁操作
这两天数据库经常被锁,所以记录一下操作: 查看被锁表:select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) ...
- ubuntu14.04安装opencv3.1
1.下载opencv3.1源码http://opencv.org/releases.html 2.安装opencv3 2.1安装opencv3的依赖 sudo apt-get install buil ...
- Oracle 体系结构chapter2
前言:Oracle 体系结构其实就是指oracle 服务器的体系结构,数据库服务器主要由三个部分组成 管理数据库的各种软件工具(sqlplus,OEM等),实例(一组oracle 后台进程以及服务器中 ...
- To My Girlfriend (DP)
题意:求选中若干个数,满足和为S,且不能选中下表i, j 和选中k, l的情况总数量. 思路:DP[i][j][k][l] i:前i个和为j,选中k个和不选中l个的情况数量,那么我们的转换应该是在必选 ...