1006. Sign In and Sign Out (25)
2015-11-04 12:27
411 查看
1.采用algorithm.h里面的sort函数,对时间进行排序,需要重写比较函数
//#include<string> //#include <iomanip> #include<vector> #include <algorithm> //#include<stack> #include<set> #include<queue> #include<map> //#include<unordered_set> //#include<unordered_map> //#include <sstream> //#include "func.h" //#include <list> #include<stdio.h> #include<iostream> #include<string> #include<memory.h> using namespace std; int time2Int(string s) { int hour = (s[0] - '0') * 10 + s[1] - '0'; int min = (s[3] - '0') * 10 + s[4] - '0'; int sec = (s[6] - '0') * 10 + s[7] - '0'; return hour * 3600 + min * 60 + sec; } struct people{ int begin, end; string ID; people() :begin(0), end(0), ID(""){}; }; bool cmpBegin(const people&a, const people&b) { if (a.begin < b.begin) return true; else return false; } bool cmpEnd(const people&a, const people&b) { if (a.end > b.end) return true; else return false; } int main(void) { int n; cin >> n; vector<people> p(n); for (int i = 0; i < n; i++) { string a, b, c; cin >> a >> b >> c; p[i].ID = a; p[i].begin = time2Int(b); p[i].end = time2Int(c); } string first = ""; sort(p.begin(), p.end(), cmpBegin); first = p[0].ID; sort(p.begin(), p.end(), cmpEnd); string last = p[0].ID; cout << first << " " << last << endl; return 0; }
相关文章推荐
- [OpenJudge-NOI]连乘积末尾0的个数
- 浅谈Hybrid技术的设计与实现(转)
- 1006. Sign In and Sign Out (25)
- 【转】STM32定时器输出比较模式中的疑惑
- C中printf 参数汇总
- [OpenJudge-NOI]乘积最大的拆分
- js返回上一页并刷新代码整理
- 1005. Spell It Right (20)
- [OpenJudge-NOI]不定方程求解 扩展欧几里德
- 这个世界上所有的人,并不是个个都有过你拥有的那些优越条件(转)
- 给Java开发者的Scala教程
- 1005. Spell It Right (20)
- MySQL常用命令
- [OpenJudge-NOI]余数相同问题 暴力
- demux的基础知识
- 英语能力
- MySQL命令行导出数据库
- jsp编程中session的用法实例分析
- Unity读取Excel数据
- Unity 3d性能优化技巧