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驱动爱好者 服务器程序员沟通交流
    如果觉得不错,欢迎点赞,你的鼓励就是我的动力
    阿里打赏 微信打赏
  • 相关阅读:
    java01 java基础知识
    01 开发准备 启动PHP服务与环境配置
    Axure 9.0 使用教程2-函数分类
    Axure 9.0 使用教程1-软件概述
    Python 字符串 列表 元组 字典 集合学习总结
    Python 函数定义 调用 迭代器 生成器 递归和推导式
    Python习题
    Python 条件 循环 及其他语句
    Python 字典
    Python 字符串
  • 原文地址:https://www.cnblogs.com/itdef/p/14396286.html
Copyright © 2011-2022 走看看