PAT (Advanced) 1006. Sign In and Sign Out (25)
来源:互联网 发布:2015年国民经济数据 编辑:程序博客网 时间:2024/05/20 20:04
原题:1006. Sign In and Sign Out (25)
解题思路:
1.设计一个结构体保存相应的id, 签到时间和签退时间。
2.分解根据签到时间和签退时间的早晚, 设计相应的排序依据的函数, 用sort函数进行排序后, 输出相应的id即可。
c++代码如下:
#include<cstdio>#include<algorithm>using namespace std;const int maxn = 10010;struct Record{ char id[20]; int h1, m1, s1; int h2, m2, s2;} record[maxn];bool cmp1(Record a, Record b) //最早开锁的排序依据{ if(a.h1 != b.h1) return a.h1 < b.h1; else if(a.m1 != b.m1) return a.m1 < b.m1; else return a.s1 < b.s1;}bool cmp2(Record a, Record b) //最晚关锁的排序依据{ if(a.h2 != b.h2) return a.h2 > b.h2; else if(a.m2 != b.m2) return a.m2 > b.m2; else return a.s2 > b.s2;}int main(){ int n; while(scanf("%d", &n) != EOF) { for(int i = 0; i < n; i++) { scanf("%s %d:%d:%d %d:%d:%d", &record[i].id, &record[i].h1, &record[i].m1, &record[i].s1, &record[i].h2, &record[i].m2, &record[i].s2); } sort(record, record + n, cmp1); printf("%s ", record[0].id); sort(record, record + n, cmp2); printf("%s\n", record[0].id); } return 0;}
阅读全文
0 0
- 【PAT Advanced Level】1006. Sign In and Sign Out (25)
- 【PAT (Advanced Level)】1006. Sign In and Sign Out (25)
- 【PAT】【Advanced Level】1006. Sign In and Sign Out (25)
- PAT (Advanced) 1006. Sign In and Sign Out (25)
- PAT(Advanced level) 1006. Sign In and Sign Out
- 浙大 PAT Advanced level 1006. Sign In and Sign Out
- 【c++】PAT (Advanced Level) 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25)
- PAT (Advanced Level) 1006. Sign In and Sign Out (25) 字符串比较
- PAT (Advanced Level) 1006. Sign In and Sign Out (25) 解题报告
- PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25)
- PAT Advanced 1006. Sign In and Sign Out (25) (C语言实现)
- PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25)
- PAT 1006. Sign In and Sign Out
- PAT 1006. Sign In and Sign Out
- 【PAT】1006. Sign In and Sign Out
- PAT-Sign In and Sign Out (25)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 C. Coconut
- UVa910 TV game
- BZOJ 3211 花神游历各国
- 网易笔试最长公共子括号序列
- 洛谷 小a和uim之大逃离
- PAT (Advanced) 1006. Sign In and Sign Out (25)
- 40:数1的个数
- 矩阵键盘
- leetcode 357
- JavaEE学习路线
- 动态二维数组类重载operator[]
- 数据结构初探
- 阅读 Tomcat 源码第一关--把 Tomcat 运行起来
- 虚拟机类加载机制