zoukankan      html  css  js  c++  java
  • 1006 Sign In and Sign Out (25 分)

    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
    题目分析:给定数据排序 ,直接利用vector对结构体排序 将比较函数重写就可以了
    注意sort中比较函数 返回true是不交换的 鉴于现在我水平较低 之后会尝试分析 源码的(大概
     1 #include<iostream>
     2 #include<string>
     3 #include<stdlib.h>
     4 #include<vector>
     5 #include<algorithm>
     6 using namespace std;
     7 #define MaxNum 1
     8 typedef struct Node {
     9     string ID_numebr;
    10     string Sign_in_time;
    11     string Sign_out_time;
    12 }S;
    13 typedef struct Time {
    14     int H;
    15     int M;
    16     int S;
    17 }T;
    18 T t1, t2;
    19 int Atoi(string str, int i, int j)
    20 {
    21     int num = 0;
    22     while (i<j)
    23     {
    24         num = num * 10 + str[i] - '0';
    25         i++;
    26     }
    27     return num;
    28 }
    29 bool comp2(const S& a, const S& b)
    30 {
    31 
    32     t1.H = Atoi(a.Sign_out_time, 0, 2);
    33     t1.M = Atoi(a.Sign_out_time, 3, 5);
    34     t1.S = Atoi(a.Sign_out_time, 6, 8);
    35     t2.H = Atoi(b.Sign_out_time, 0, 2);
    36     t2.M = Atoi(b.Sign_out_time, 3, 5);
    37     t2.S = Atoi(b.Sign_out_time, 6, 8);
    38     if (t1.H > t2.H)
    39         return true;
    40     else if (t1.H == t2.H && t1.M > t2.M)
    41         return true;
    42     else if (t1.M == t2.M && t1.S > t2.S)
    43         return true;
    44     else
    45         return false;
    46 }
    47 
    48 bool comp1(const S& a, const S& b)
    49 {
    50 
    51     t1.H = Atoi(a.Sign_in_time, 0, 2);
    52     t1.M = Atoi(a.Sign_in_time, 3, 5);
    53     t1.S = Atoi(a.Sign_in_time, 6, 8);
    54     t2.H = Atoi(b.Sign_in_time, 0, 2);
    55     t2.M = Atoi(b.Sign_in_time, 3, 5);
    56     t2.S = Atoi(b.Sign_in_time, 6, 8);
    57     if (t1.H < t2.H)
    58         return true;
    59     else if (t1.H == t2.H && t1.M < t2.M)
    60         return true;
    61     else if (t1.M == t2.M && t1.S < t2.S)
    62         return true;
    63     else
    64         return false;
    65 }
    66 
    67 int main()
    68 {
    69     vector<Node> N;
    70     S s;
    71     int n;
    72     cin >> n;
    73     for (int i = 0; i < n; i++)
    74     {
    75         cin >> s.ID_numebr >> s.Sign_in_time >> s.Sign_out_time;
    76         N.push_back(s);
    77     }
    78     sort(N.begin(), N.end(), comp1);
    79     cout << N[0].ID_numebr<<" ";
    80     sort(N.begin(), N.end(), comp2);
    81     cout << N[0].ID_numebr;
    82     return 0;
    83 }
    View Code
  • 相关阅读:
    ActionBar Fragment的一个sample activity; 及获取runningAppProcess及跳转
    优化后台推送的service,减少被杀死的几率
    64位win7安装ubunto最新14.04的过程,及出现的问题的解决
    一次非线上iowait高的情况的检查
    一个愚蠢的python逻辑语法错误
    Bellman-Ford算法解决单源最短路问题
    Floyd算法解决多源最短路径问题
    最短路问题Dijkstra算法
    最小生成树之Kruskal算法
    最优二叉搜索树
  • 原文地址:https://www.cnblogs.com/57one/p/11858983.html
Copyright © 2011-2022 走看看