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. C# 通过hessian调Java注意事项

    照理说C#可以通过标准的web服务可以轻松地调用Java,但是鉴于hessian的高性能及开发效率,个人认为C#通过hessian调用java是很值得提倡的.之前完成的一个比较大型的企业应用项目就是采 ...

  2. 转载[POJ题型分类]

    北大ACM题分类 主流算法: 1.搜索 //回溯 2.DP(动态规划) 3.贪心 4.图论 //Dijkstra.最小生成树.网络流 5.数论 //解模线性方程 6.计算几何 //凸壳.同等安置矩形的 ...

  3. 写个接口的实现类,在方法的前面加了@Override居然报错

    据说这是jdk的问题,@Override是JDK5就已经有了,但有个小小的Bug,就是不支持对接口的实现,认为这不是Override 而JDK6修正了这个Bug,无论是对父类的方法覆盖还是对接口的实现 ...

  4. OC - 28.模拟时钟

    效果图 实现思路 该示例通过隐式动画实现 表盘通过显示在imageView中的一张图片来实现 在表盘上绘制(时分秒)三条直线,分别位于不同的图层,且时针位于最下层,秒针位于最上层 设置直线为圆角 直线 ...

  5. Delphi动态创建组件,并释放内存

    开发所用delphi版本是xe2,效果图如下: 代码如下: ---------------------------------------------------------------------- ...

  6. ajax 操作全局监测,用户session失效

    jQuery(function ($) { // 备份jquery的ajax方法 var _ajax = $.ajax; // 重写ajax方法,先判断登录在执行success函数 $.ajax = ...

  7. Android 学习手札(备注)

    1.在Android 应用程序中不能使用System.out.println(..)来输出信息,而要使用Log类中的静态方法输出调试信息. Log.d("onStart", &qu ...

  8. 子元素的margin-top影响父元素原因和解决办法

    这个问题会出现在所有浏览器当中,原因是css2.1盒子模型中规定, In this specification, the expression collapsing margins means tha ...

  9. wechat-php-sdk

    wechat-php-sdk 微信公众平台php版开发包 支持消息加解密方式的明文模式.兼容模式.安全模式 支持自动接入微信公众平台(步骤) 功能模块 Wechat (处理自动接入.获取与回复微信消息 ...

  10. NSEnumerator用法小结

    NSEnumerator   3)枚举 (NSEnumerator)遍历数组每个索引处的对象,你可以编写一个0到[array count]的循环,而NSEnumerator用来描述这种集合迭代运算的方 ...