题目描述
在ACM竞赛中,当遇到有两个队伍(人) 解出相同的题目数量的时候,我们需要通过他们解决问题的总时间进行排序。
一共有 N(1<=N<=5,000)条时间被以时(0<=Hours<=99), 分(0<=Minutes<=59),秒(0<=Seconds<=59)的形式记录。
你必须要把他们按时,分,秒排序为 升序,最少的时间最先。 考虑到如下的样例,这三个解出相同题目数量的时间为
11:20:20
11:15:12
14:20:14
正确的排序结果应该是这样的:
11:15:12
11:20:20
14:20:14
输入描述:
第 1 行,一个整数 N 第 2~n+1 行,每行 3 个整数,表示时,分,秒
输出描述:
共 n 行,每行 3 个整数,表示排序完后的结果
示例1
输入
3 11 20 20 11 15 12 14 20 14
输出
11 15 12 11 20 20 14 20 14
说明
所以在保证能做对的情况下,我们应当尽量减少罚时
思路
简单的结构体排序,写好排序规则就行了,依次比较时分秒即可
代码
//竞赛技巧(排序)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 5e4 + 10;
struct Time
{
int hour;
int minute;
int second;
bool operator < (const Time t) const
{
if(this->hour != t.hour)
return this->hour < t.hour;
if(this->minute != t.minute)
return this->minute < t.minute;
return this->second < t.second;
}
};
int n;
Time times[N];
int main()
{
scanf("%d" , &n);
for(int i = 0 ; i < n ; i++)
scanf("%d %d %d" , ×[i].hour , ×[i].minute , ×[i].second);
sort(times , times + n);
for(int i = 0 ; i < n ; i++)
printf("%d %d %d\n" , times[i].hour , times[i].minute , times[i].second);
return 0;
} 
京公网安备 11010502036488号