首页 > 其他分享 >HDOJ2115 I Love This Game

HDOJ2115 I Love This Game

时间:2023-02-20 11:01:53浏览次数:35  
标签:Love name int rank ++ Game HDOJ2115 time String


I Love This Game


Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8290    Accepted Submission(s): 2864


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


 


将时间转换为分(假设是 --时:分),然后排序(时间相同的按名字排)



import java.util.Scanner;

public class Main{
private static Scanner scanner;
private static int t[];
private static String name[];

public static void main(String[] args) {
scanner = new Scanner(System.in);
int cases = 1;// 计算次数
boolean boo = false;
while (scanner.hasNext()) {
int n = scanner.nextInt();
if (n == 0) {
break;
}

name = new String[n];// 名字
String time[] = new String[n];// 时间
//接收数据
for (int i = 0; i < n; i++) {
name[i] = scanner.next();
time[i] = scanner.next();
}
t = new int[n];// 时间
// 计算时间
// 全部转化为分
for (int i = 0; i < n; i++) {
String[] split = time[i].split(":");
int h = Integer.parseInt(split[0]);
int m = Integer.parseInt(split[1]);
t[i] = h * 60 + m;
}
sort();// 进行排序
/*for (int i = 0; i < time.length; i++) {
System.out.println(t[i]);
}*/
if(boo){//不是第一个就先输出空行
System.out.println();
}
System.out.println("Case #"+cases);
int rank[] = new int[n];
rank[0] = 1;//排名
//先输出第一个
System.out.println(name[0]+" "+rank[0]);
for (int i = 1; i < n; i++) {
if(t[i] == t[i-1]){
rank[i] = rank[i-1];
}else {
rank[i] = i+1;
}
System.out.println(name[i]+" "+rank[i]);
}

cases++;
boo = true;
}
}

// 排序
private static void sort() {
for (int i = 0; i < name.length - 1; i++) {
for (int j = i + 1; j < name.length; j++) {
if (t[i] > t[j]) {// 时间从小到大
swap(i, j);
} else if (t[i] == t[j]) {
if (name[i].compareTo(name[j]) > 0){
swap(i, j);
}
}
}
}
}

// 交换
private static void swap(int i, int j) {
int temp = t[i];
t[i] = t[j];
t[j] = temp;

String string = name[i];
name[i] = name[j];
name[j] = string;
}
}



标签:Love,name,int,rank,++,Game,HDOJ2115,time,String
From: https://blog.51cto.com/u_15741949/6067975

相关文章

  • games104 现代游戏引擎 Picoolo环境搭建 vulkan配置
    0前言介绍games104现代游戏引擎课程是由GAMES:GraphicsAndMixedEnvironmentSymposium支持的一个课程。如我们所视,Games并非的含义并不是游戏,而是计算机图形学......
  • CF1037G A Game on Strings Sol
    有趣题。首先"分成若干个互不相干的子串"是子游戏的定义,可以用SG函数处理。然而接下来试着打了半个多小时的表,没有找到任何规律。但是发现SG函数的状态转移是很简单......
  • uniapp开发在hbuilderx运行小程序时微信开发者工具编辑出错:error:game.json:未找到gam
      uniapp开发在hbuilderx运行小程序时微信开发者工具编辑出错:error:game.json:未找到game.json文件,或者文件读取失败处理。是因为我当前登录微信开发者账号是开发小程......
  • 【CF207C3】Game with Two Trees
    【CF207C3】GamewithTwoTreesDescription有两颗动态加入点的树,每条边有一个字符每次加入完点后T1中到根的链在T2中的匹配次数之和Input一行一个数\(q\)Output输......
  • hgame2023
    hgame2023week1‍test_ncnc签到‍easy_overflow​​有后门pl=b'a'*0x18+p64(0x40117E)p.sendline(pl)​​close(1)关闭了标准输出首先我们要明白什么是标准输......
  • C、Grid game 【 Codeforces Round #534 (Div. 2) 】
    C、Gridgame题意:给你一个4×4的方格,然后给你一些1×2或者2×1的小方格,当这些方格在一行或者一列的时候会消除掉,问最佳放置位置。思路:QAQ,什么时候思维会变强......
  • Fire Game (FZU 2150)(BFS)
    题解:一开始想错了,以为只要烧完就是那个答案,但是这不是最优的结果,需要每两个点都bfs一遍,找到如果能够全部烧完,找到花费时间最小的,如果不能return-1。在bfs的时候,记录答案......
  • CF446C DZY Loves Fibonacci Numbers 题解和加强
    简要题意https://www.luogu.com.cn/problem/CF446C给定一个长度为\(n\)的序列\(A\),要求支持两种操作:1给定区间\((l,r)\)对这个区间内的每个数,依次加斐波那契数列......
  • 使用精灵组对精灵成员编队 pygame 230213
    定义精灵成员定义了两个精灵成员说明:Background类是精灵类的子类定义精灵组精灵组添加精灵语法:精灵组.add(精灵成员)批量更新数据语法:精灵组.update()说明:目的是让所有的精灵......
  • GPT-3 vs Bert vs GloVe vs Word2vec 文本嵌入技术的性能对比测试
    随着NLP(自然语言处理)的最新进展,OpenAI的GPT-3已经成为市场上最强大的语言模型之一。2022年1月25日,OpenAI公布了一个embeddingendpoint(Neelakantanetal.,2022)。该神......