{"id":473,"date":"2013-08-09T20:04:00","date_gmt":"2013-08-09T12:04:00","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=473"},"modified":"2013-08-09T20:04:00","modified_gmt":"2013-08-09T12:04:00","slug":"1006-sign-in-and-sign-out-25","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=473","title":{"rendered":"1006. Sign In and Sign Out (25)"},"content":{"rendered":"<p>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&#8217;s and out&#8217;s, you are supposed to find the ones who have unlocked and locked the door on that day.<br \/>\n<b>Input Specification:<\/b><br \/>\nEach 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:<\/p>\n<pre>ID_number Sign_in_time Sign_out_time<\/pre>\n<p>where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.<br \/>\n<b>Output Specification:<\/b><br \/>\nFor 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.<br \/>\nNote: 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.<br \/>\n<b>Sample Input:<\/b><\/p>\n<pre>3\nCS301111 15:30:28 17:00:10\nSC3021234 08:00:00 11:25:25\nCS301133 21:45:00 21:58:40<\/pre>\n<p><b>Sample Output:<\/b><\/p>\n<pre>SC3021234 CS301133<\/pre>\n<p>========================<br \/>\n\u6ca1\u4ec0\u4e48\u6280\u672f\u542b\u91cf\uff0c\u76f4\u63a5\u8d34\u4ee3\u7801~\uff01<br \/>\n========================<\/p>\n<pre>\n#include <stdio.h>\n#include <string.h>\n#include <map>\nusing namespace std;\nint compare(int left[], int right[])\n{\n    \/\/\u6bd4\u8f83\u4e24\u4e2a\u65f6\u95f4\u7684\u5927\u5c0f\uff0cleft\u6bd4right: \u65e9\u8fd4\u56de-1\uff0c \u76f8\u7b49\u8fd4\u56de0\uff0c \u665a\u8fd4\u56de1\n    if(left[0] > right[0])\n        return 1;\n    else if(left[0] < right[0])\n        return -1;\n    else\n    {\n        if(left[1] > right[1])\n            return 1;\n        else if(left[1] < right[1])\n            return -1;\n        else\n        {\n            if(left[2] > right[2])\n                return 1;\n            else if(left[2] < right[2])\n                return -1;\n            return 0;\n        }\n    }\n}\nint main()\n{\n    int sign_in_time[3] = {23, 59, 59};  \/\/hh,mm,ss\n    int sign_out_time[3] = {0, 0, 0};\n    char sign_in_user[15]; \/\/\u6700\u65e9\u767b\u5165\u7684\n    char sign_out_user[15]; \/\/\u6700\u8fdf\u767b\u51fa\u7684\n    int M = 0;\n    scanf(\"%d\", &#038;M);\n    for(int i=0; i<m; i++)\n    {\n        char id[15];\n        int in[3], out[3];\n        scanf(\"%s %d:%d:%d %d:%d:%d\", id, &#038;in[0], &#038;in[1], &#038;in[2], &#038;out[0], &#038;out[1], &#038;out[2]);\n        int cmp_in = compare(in, sign_in_time);\n        \/\/\u5982\u679c\u767b\u5f55\u65f6\u95f4\u6bd4\u5f53\u524d\u7684\u65e9\n        if(cmp_in == -1)\n        {\n            strcpy(sign_in_user, id);\n            for(int t=0; t<3; t++)\n                sign_in_time[t] = in[t];\n        }\n        int cmp_out = compare(out, sign_out_time);\n        if(cmp_out == 1)\n        {\n            strcpy(sign_out_user, id);\n            for(int t=0; t<3; t++)\n                sign_out_time[t] = out[t];\n        }\n    }\n    printf(\"%s %s\", sign_in_user, sign_out_user);\n    return 0;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s and out&#8217;s, you are supposed to find the ones who have unlocked and locked the door on that day. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[84],"class_list":["post-473","post","type-post","status-publish","format-standard","hentry","category-study","tag-pat"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=473"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/473\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}