1006. Sign In and Sign Out (25)
来源:互联网 发布:24美元曼哈顿复利 知乎 编辑:程序博客网 时间:2024/04/29 03:44
1006. Sign In and Sign Out (25)
Question
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in’s and out’s, you are supposed to find the ones who have unlocked and locked the door on that day.
Input Specification:
Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:
ID_number Sign_in_time Sign_out_time
where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.
Output Specification:
For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.
Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.
Sample Input:
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
Sample Output:
SC3021234 CS301133
#include <iostream>#include <map>#include <string>#include <vector>#include <stdio.h>#include <stdlib.h>using namespace std;bool AisEearlyThenB(string A, string B) { //拆分时间A和B char *A_time = (char*)A.data(); char *B_time = (char*)B.data(); int Atime[3], Btime[3]; sscanf(A_time, "%d:%d:%d", &Atime[0], &Atime[1], &Atime[2]); sscanf(B_time, "%d:%d:%d", &Btime[0], &Btime[1], &Btime[2]); if (Atime[0] == Btime[0]) { if (Atime[1] == Btime[1]) { return Atime[2] < Btime[2]; } else { return Atime[1] < Btime[1]; } } else { return Atime[0] < Btime[0]; }}int main(int argc, const char * argv[]) { map<string, vector<string>> records; int M; cin >> M; for (int i = 0; i < M; ++i) { string ID, signInTime, signOutTime; cin >> ID >> signInTime >> signOutTime; vector<string> date; date.push_back(signInTime); date.push_back(signOutTime); records[ID] = date; } string openDoorID, lockDoorID; string earlyComeInTime, lateLeaveTime; map<string, vector<string>>::iterator map_ite; //指向record第一个pair //每一个人 for (map_ite = records.begin(); map_ite != records.end(); ++map_ite) { //初始的id和时间 if (map_ite == records.begin()) { openDoorID = (*map_ite).first; lockDoorID = (*map_ite).first; earlyComeInTime = (*map_ite).second.at(0); lateLeaveTime = (*map_ite).second.at(1); } else { //其他id的时间与初始的进行比较 string ID, comeTime, leaveTime; ID = (*map_ite).first; comeTime = (*map_ite).second.at(0); leaveTime = (*map_ite).second.at(1); if (AisEearlyThenB(comeTime, earlyComeInTime)) { openDoorID = ID; } if (!AisEearlyThenB(leaveTime, lateLeaveTime)) { lockDoorID = ID; } } } cout << openDoorID << " " << lockDoorID << endl; return 0;}
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 关于Xcode的绝对路径和相对路径问题
- 作业
- UI - Cocoa Touch框架
- docker 安装 webpack 时报错 EPROTO: protocol error, symlink
- C语言字符串strlen函数使用
- 1006. Sign In and Sign Out (25)
- 从零开始学_JavaScript_系列(五)——dojo(基础,动画移动,重力模拟,动画合并,添加标签)
- 在Sqlserver中添加删除约束!
- play模板twirl
- 浏览器渲染原理及解剖浏览器内部工作原理
- SAP 物料主数据屏幕增强
- Spark RDD系列----3. rdd.coalesce方法的作用
- vb
- 第1周 项目(A)-8分离整数和小数部分