Problem Description

Do you like playing basketball ? If you are , you may know the NBA Skills Challenge . It is the content of the basketball skills . It include several parts , such as passing , shooting , and so on. After completion of the content , the player who takes the shortest time will be the winner . Now give you their names and the time of finishing the competition , your task is to give out the rank of them ; please output their name and the rank, if they have the same time , the rank of them will be the same ,but you should output their names in lexicographic order.You may assume the names of the players are unique.

Is it a very simple problem for you? Please accept it in ten minutes.

Input

This problem contains multiple test cases! Ease test case contain a n(1<=n<=10) shows the number of players,then n lines will be given. Each line will contain the name of player and the time(mm:ss) of their finish.The end of the input will be indicated by an integer value of zero.

Output

The output format is shown as sample below.

Please output the rank of all players, the output format is shown as sample below;

Output a blank line between two cases.

Sample Input

10

Iverson 17:19

Bryant 07:03

Nash 09:33

Wade 07:03

Davies 11:13

Carter 14:28

Jordan 29:34

James 20:48

Parker 24:49

Kidd 26:46

0

Sample Output

Case #1

Bryant 1

Wade 1

Nash 3

Davies 4

Carter 5

Iverson 6

James 7

Parker 8

Kidd 9

Jordan 10

题目大意就是按照后面的时间排名,所用时间小的排前面,如果时间相等,按照名字的字典序排序。不会出现相同的名字。

用sort方法给它们排序好,再输出就行,注意,这里的难点是输出的时候,

排名相同的人,他们的名次必须另外用一个数来标志。

还有,输出的时候,2个输出之间有空行。

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner; public class Main{ public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t =0;
while(sc.hasNext()){
int n =sc.nextInt();
if(n==0){
break;
}
if(t!=0){
System.out.println();
}
Stu stu[] = new Stu[n];
for(int i=0;i<n;i++){
stu[i] = new Stu();
stu[i].name=sc.next();
String str = sc.next();
String strs[] = str.split(":");
stu[i].h=Integer.parseInt(strs[0]);
stu[i].m=Integer.parseInt(strs[1]);
stu[i].d=i;//必须赋值不同的值
}
Arrays.sort(stu, new Comparator<Stu>() {
@Override
public int compare(Stu o1, Stu o2) {
if(o1.h>o2.h){
return 1;
}
if(o1.h<o2.h){
return -1;
}
if(o1.m>o2.m){
return 1;
}
if(o1.m<o2.m){
return -1;
}
//-1用来标识这个2个人的时间相等
o1.d=-1;
o2.d=-1;
return o1.name.toUpperCase().compareTo(o2.name.toUpperCase());
}
}); System.out.println("Case #"+(++t));
int h=1;//h是从1-n依次加一的数
int k=1;//如果有重复排名时的排名
int eq =1;//用来标识有几个重复的
for(int i=0;i<n;i++){
k=h-eq;//重复的时间有几次,就用h减去它,就是排名
if(i==0){
System.out.println(stu[i].name+" "+(h++));
}else{
if(stu[i].d==stu[i-1].d){//这个2个人的时间相等
eq++;
System.out.println(stu[i].name+" "+k);
h++;
}else{
eq=1;
System.out.println(stu[i].name+" "+(h++));
}
}
}
}
}
} class Stu{
String name;
int h;
int m;
int d;
}

HDOJ(HDU) 2115 I Love This Game(排序排序、、、)的更多相关文章

  1. HDOJ/HDU 2561 第二小整数(水题~排序~)

    Problem Description 求n个整数中倒数第二小的数. 每一个整数都独立看成一个数,比如,有三个数分别是1,1,3,那么,第二小的数就是1. Input 输入包含多组测试数据. 输入的第 ...

  2. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  3. HDOJ(HDU).1864 最大报销额 (贪心)

    HDOJ(HDU).1864 最大报销额 题意分析 题目有点问题,原题中说的 单项物品的价值不得超过600元 应该是单类物品的价值不能超过600元. 一开始以为是01背包,后来按贪心写过了. 一张一张 ...

  4. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  5. HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)

    HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和ric ...

  6. HDOJ(HDU).1015 Safecracker (DFS)

    HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...

  7. HDOJ(HDU).1412 {A} + {B} (STL SET)

    HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...

  8. HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...

  9. HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)

    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...

随机推荐

  1. 处理移动端click事件300ms延迟的好方法—FastClick

    下载地址:https://github.com/ftlabs/fastclick 1.click事件为什么有延迟? “...mobile browsers will wait approximatel ...

  2. jQuery注册验证

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 初识 Angular 体会

    一句话描述:一个前端的类似MVC框架的JS库 刚接触2天,刚一看感觉和asp.net mvc能实现的功能有点重复. 虽然asp.net的表单验证,Razor语法使其在前端开发有较大提升,但要实现比较高 ...

  4. 控件AutoCompleteTextView实现动态匹配输入内容的一种输入框

    <AutoCompleteTextView android:layout_width="match_parent" android:layout_height="w ...

  5. linux 命令学习(4)

    Linux中常用的关机和重新启动命令有shutdown.halt.reboot以及init,它们都可以达到关机和重新启动的目的,但是每个命令的内部工作过程是不同的,下面将逐一进行介绍. 1. shut ...

  6. 强大的Core Image框架,各种滤镜处理图像

    首先介绍一下Core Image,他是一个很强大的图像处理框架,他可以让你简单的应用各种滤镜来处理图像,比如说色相,饱和度,亮度等等...他是运用GPU(CPU)实时地处理图像数据和视频的帧.而且Co ...

  7. C# 枚举

    一.在学习枚举之前,首先来听听枚举的优点. 1.枚举能够使代码更加清晰,它允许使用描述性的名称表示整数值. 2.枚举使代码更易于维护,有助于确保给变量指定合法的.期望的值. 3.枚举使代码更易输入. ...

  8. [转]PHP取整函数:ceil,floor,round,intval的区别详细解析

    我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. 1.ceil -- 进一法取整 说明float ceil ( float value ) 返回不小于 value ...

  9. 『重构--改善既有代码的设计』读书笔记----Replace Data Value with Object

    当你在一个类中使用字段的时候,发现这个字段必须要和其他数据或者行为一起使用才有意义.你就应该考虑把这个数据项改成对象.在开发初期,我们对于新类中的字段往往会采取简单的基本类型形式来保存,但随着我们开发 ...

  10. iframe中在父窗口打开子页面

    我们在做页面框架的时候,通常会采用一个iframe来显示子页面,但有这么种情况,就是session失效时,登录页面就会显示在iframe中,这不符合常理,一般应该显示在顶部才对. 下面的js代码可以解 ...