zoukankan      html  css  js  c++  java
  • PAT 甲级 1006 Sign In and Sign Out 字符串

    地址  https://pintia.cn/problem-sets/994805342720868352/problems/994805516654460928

    题目大意是 按照HH:MM:SS 形式输入一个员工的签到签出时间,要求我们找到最早签到和最晚签出的员工id

    输入格式

    第一行 一个整数 N 表示有N个员工

    下面N行的格式是  ID_number Sign_in_time Sign_out_time

    ID_number 是员工ID Sign_in_time 是签到时间   Sign_out_time是签出时间

    输出格式

    ID_number  ID_number 

    找到最早签到和最晚签出的员工id 用空格隔开

    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

    考核点 字符串排序
    我们可以观察到 如果将时间按照字典序排序
    那么最早的时间就是第一个
    如果逆序排序 最晚的时间就是第一个
    所以使用STL进行时间字符串排序就可以解决该题

    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    
    using namespace std;
    
    vector<string> vv[1010];
    int n;
    
    
    bool sortOut(const vector<string>& a, const vector<string>& b)
    {
        if (a[2] < b[2]) return false;
    
        return true;
    }
    
    bool sortIn(const vector<string>& a, const vector<string>& b)
    {
        if (a[1] > b[1]) return false;
    
        return true;
    }
    
    int main() {
        cin >> n;
        for (int i = 0; i < n; i++) {
            string name, in, out;
            cin >> name >> in >> out;
            vv[i].push_back(name);
            vv[i].push_back(in);
            vv[i].push_back(out);
        }
        sort(&vv[0], &vv[0] + n, sortIn);
        cout << vv[0][0] << " ";
    
        sort(&vv[0], &vv[0] + n, sortOut);
        cout << vv[0][0] << endl;
    
        return 0;
    }
     
    作 者: itdef
    欢迎转帖 请保持文本完整并注明出处
    技术博客 http://www.cnblogs.com/itdef/
    B站算法视频题解
    https://space.bilibili.com/18508846
    qq 151435887
    gitee https://gitee.com/def/
    欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
    如果觉得不错,欢迎点赞,你的鼓励就是我的动力
    阿里打赏 微信打赏
  • 相关阅读:
    [bzoj4241] 历史研究 (分块)
    [tyvj2054] 四叶草魔杖 (最小生成树 状压dp)
    20180710 考试记录
    [luogu2047 NOI2007] 社交网络 (floyed最短路)
    [luogu2081 NOI2012] 迷失游乐园 (树形期望dp 基环树)
    [luogu1600 noip2016] 天天爱跑步 (树上差分)
    [luogu2216 HAOI2007] 理想的正方形 (2dST表 or 单调队列)
    [poj 3539] Elevator (同余类bfs)
    [BZOJ1999] 树网的核 [数据加强版] (树的直径)
    bzoj2301 [HAOI2011]Problem b
  • 原文地址:https://www.cnblogs.com/itdef/p/14396286.html
Copyright © 2011-2022 走看看