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. SQL Server死锁日志各字段含义

    使用跟踪标记 1204 --打开跟踪标记 DBCC TRACEON (1204,-1) --关闭跟踪标记 DBCC TRACEOFF (1204,-1) 处于死锁状态时,跟踪标记 1204 在等待的线 ...

  2. 表单提交对chrome记住密码的影响

    在处理注册.登录等含有用户名,密码的元素的表单时,chrome会主动的提示记住密码,然而这个功能在用户名的选择上真是耐人寻味,它总是寻找离password input控件最近的那一个文本框的内容,作为 ...

  3. vpn的作用

    1.可以用于远程对方桌面. 步骤: 1.浏览器中访问网址,输入用户名,密码即可 2.输入远程桌面用户名和网址

  4. vim备注

    ① 用户path生效 在~/.bashrc中修改path,在~/.profile中source bashrc ② secureCRT着色方案 底色RGB:43 43 43 前景色RGB:221 221 ...

  5. iOS菜鸟之苹果开发者账号的注册

    大家一起来讨论讨论苹果开发者账号的注册(主要是以公司的开发者账号为例),前段时间公司要求注册开发者账号,于是我就特地看了看相关的帖子.这里简单给大家总结一下具体的流程. 首先你要登陆这个网址,进去之后 ...

  6. 不用Google Adsense的84个赚钱方法

    这是一个关于网络广告商和网络销售的汇总列表,可以用来为您的网站或博客赚点钱.广告商都是英文的,加入广告请确认其是否支持中国地区支持,不支持的话就不必加入了. Chitika : 购物中心旗帜广告. ( ...

  7. (JAVA)从零开始之--对象输入输出流ObjectInputStream、ObjectOutputStream(对象序列化与反序列化)

    对象的输入输出流 : 主要的作用是用于写入对象信息与读取对象信息. 对象信息一旦写到文件上那么对象的信息就可以做到持久化了 对象的输出流: ObjectOutputStream 对象的输入流:  Ob ...

  8. 几种不同存储形式下的数据挖掘问题[ZZ]

    从原理上说,数据挖掘应该可以应用到任何信息存储方式的知识挖掘中,但是挖掘的挑战性和技术会因为源数据的存储类型的不同而不同.特别是,近年来的研究表明数据挖掘所涉及的数据存储类型越来越丰富,除了一些有通用 ...

  9. 根据CreateDirectory递归创建多级目录

    分为MFC下的和非MFC下的两种,MFC路径是CString类型的,非MFC的路径是wstring类型的. 下面是MFC下的创建目录: void __fastcall RecursiveDirecto ...

  10. linux定时执行python脚本

    每天清晨 4:00:01,用python执行/opt/aa.py文件. 编辑定时任务: #crontab -e 加入: 0 4 * * * python /opt/aa.py 保存,退出即可. 如果执 ...