已解决
竞赛技巧#
来自网友在路上 157857提问 提问时间:2023-10-05 19:18:51阅读次数: 57
最佳答案 问答题库578位专家为你答疑解惑
链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
题目描述
在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
3 11 20 20 11 15 12 14 20 14
输出
复制11 15 12 11 20 20 14 20 14
11 15 12 11 20 20 14 20 14
#include <iostream>
#include <vector>
#include <algorithm>struct Time {int hours;int minutes;int seconds;
};bool compareTime(const Time& t1, const Time& t2) {if (t1.hours != t2.hours) {return t1.hours < t2.hours;} else if (t1.minutes != t2.minutes) {return t1.minutes < t2.minutes;} else {return t1.seconds < t2.seconds;}
}int main() {int n;std::cin >> n;std::vector<Time> times(n);for (int i = 0; i < n; i++) {std::cin >> times[i].hours >> times[i].minutes >> times[i].seconds;}std::sort(times.begin(), times.end(), compareTime);for (int i = 0; i < n; i++) {std::cout << times[i].hours << " " << times[i].minutes << " " << times[i].seconds << std::endl;}return 0;
}
查看全文
99%的人还看了
相似问题
猜你感兴趣
版权申明
本文"竞赛技巧#":http://eshow365.cn/6-15930-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: MIP精确算法的关键——确定界
- 下一篇: 基于Kylin的数据统计分析平台架构设计与实现