I Love This Game 2115
2014-03-22 21:20
246 查看
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
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
#include <iostream> #include <string> #include <algorithm> #include <cstdio> struct people { std::string strName; int nH; int nM; bool operator<(const people &rhs) const { if(nH < rhs.nH) { return true; } else if(nH == rhs.nH && nM < rhs.nM) { return true; } else if(nH == rhs.nH && nM == rhs.nM && strName < rhs.strName) { return true; } else { return false; } } }; int main(int argc, const char *argv[]) { int n, nCount = 1; bool bFlag = true; while(std::cin >> n && n != 0) { if(bFlag) { bFlag = false; } else { std::cout << std::endl; } people p[10]; for(int i = 0;i < n;++ i) { std::cin >> p[i].strName; scanf("%d:%d", &p[i].nH, &p[i].nM); } std::sort(p, p + n); std::cout << "Case #" << nCount << std::endl; int nRank = 1; for(int i = 0;i < n;++ i) { if(i != 0 && (p[i].nH != p[i - 1].nH || p[i].nM != p[i - 1].nM)) { nRank = i + 1; } std::cout << p[i].strName << " " << nRank << std::endl; } ++ nCount; } //system("pause"); return 0; }
相关文章推荐
- 连载:面向对象葵花宝典:思想、技巧与实践(5) - 面向对象迷思:面向对象导致性能下降?
- 公钥私钥 加密解密
- 数据库in/exists用法和效率大揭密
- string相关函数的功能实现案例
- Unique PatUnique Paths II
- ural 1333 Genie Bomber 2
- JS简单数据类型和引用类型
- ACM在线题库
- C语言基础笔试面试题
- 在html中以applet的形式展示worldwind
- js_day24--js DOM编程(document+body对象)
- 用tornado ,Supervisord ,nginx架网站
- 学习IOS开发的第10天
- 2014第12周六
- Android webkit 时代结束,我们需要做些什么准备?
- 大龙在win7下安装SQL Server 2008 r2的悲惨经历
- Flex 4 开发后台管理系统(2)
- [DataTable] datatable根据表中的字段进行排序
- 重装VMware workstation
- pat 1034