zoukankan      html  css  js  c++  java
  • HDU 2115 I Love This Game

    http://acm.hdu.edu.cn/showproblem.php?pid=2115

    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

    时间复杂度:$O(N * logN)$

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int N;
    
    struct Player {
        char name[300];
        int hh;
        int mm;
        int Time;
    }player[150];
    
    bool cmpTime( Player& a,  Player& b) {
        if(a.Time == b.Time)
            return strcmp(a.name, b.name) < 0;
        return a.Time < b.Time;
    }
    
    int main() {
        int casee = 1;
        while(~scanf("%d", &N)) {
            
            if(!N) break;
            if(casee!=1)
                printf("
    ");
            printf("Case #%d
    ", casee ++);
    
            for(int i = 1; i <= N; i ++) {
                scanf("%s %d:%d", player[i].name, &player[i].hh, &player[i].mm);
                player[i].Time = player[i].hh * 60 + player[i].mm;
            }
    
            sort(player + 1, player + 1 + N, cmpTime);
    
            int num = 1;
            
            for(int i = 1; i <= N; i ++) {
                printf("%s ", player[i].name);
                if(player[i].Time == player[i - 1].Time)
                    printf("%d
    ", num);
                else {
                    num = i;
                    printf("%d
    ", num);
                }
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    candy——动态规划
    HTTP协议(转)
    linked-list-cycle-ii——链表,找出开始循环节点
    linked-list-cycle——链表、判断是否循环链表、快慢指针
    转: utf16编码格式(unicode与utf16联系)
    【转】Nginx模块开发入门
    【转】依赖注入那些事儿
    转: OpenResty最佳实践
    转:linux的源码查看, c++语法 查看网站
    【转】所需即所获:像 IDE 一样使用 vim
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9630409.html
Copyright © 2011-2022 走看看