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. 谁是谁的first-child

    看过CSS伪类选择器之后,心想也就如此嘛,:first-child选择元素的第一个子元素,有什么难的,可一到实践中,还是到处碰壁啊. <body> <ul class="f ...

  2. jq 图片上传

    1.html <input type="file" class="ImgInput" name="ImgInput"/> 2.j ...

  3. 【转】jQuery教程

    “jQuery风暴” 推荐及配套代码下载 ziqiu.zhang 2011-03-24 00:28 阅读:15339 评论:100   从零开始学习jQuery(剧场版) 你必须知道的javascri ...

  4. Unity 5.x---00使用重力

    Unity 5.x---00使用重力 步骤一: 打开一个工程(导入Unity自带的资源),并创建并配置好必要的GameObject ,如下图: 步骤二: 1.创建一个Cube,使其位于平面上方.    ...

  5. linux 监控服务器脚本

    #!/bin/bash ctime=`date +%x%T`monitor_dir=/home/jk/if [ ! -d $monitor_dir ]; then    mkdir $monitor_ ...

  6. 关于Function()函数对象的那些小九九

    概念:首先,函数是一种特殊类型的数据,函数也是数据类型的一种,实际上函数也是一种对象,函数对象的内建构造器是Function(); 函数的几种创建方式: 函数声明法: function sum(a,b ...

  7. DEDECMS栏目自定义字段添加

    用到的文件: catalog_add.htm  路径:\dede\templets\ catalog_edit.htm  路径:\dede\templets\  catalog_add.php  路径 ...

  8. 3.1决策树理论--python深度机器学习

    参考彭亮老师的视频教程:转载请注明出处及彭亮老师原创 视频教程: http://pan.baidu.com/s/1kVNe5EJ   0. 机器学习中分类和预测算法的评估:   准确率 速度 强壮行 ...

  9. Java中间件

    传统的HTML已经满足不了如今web系统的诸多的功能需求,建立一个交互式的Web,便诞生了各种Web开发语言,如ASP,JSP,PHP等,这些语言与传统的语言有着密切的联系,如JSP基于Java语言. ...

  10. 支付宝集成获取私钥与公钥-b

    项目需要,需要在客户端集成支付宝接口.就研究了一下:因为使用支付宝接口,就需要到支付宝官网:注册帐号,并申请.下面讲的是申请好之后的操作.登录成功之后,   店家我的商家服务—在页面的下方找到——&g ...