1006. Sign In and Sign Out (25)

本文介绍了一个使用C++编写的程序,该程序通过定义结构体来表示时间,并实现了一个比较两个时间先后的功能。程序读取一系列时间记录,找出最早和最晚的时间点。
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>

#include <string>

using namespace std;

struct node//时间
{
    int hh;
    int mm;
    int ss;
};

bool later(node n1,node n2)//如果n1比n2晚,返回真,否则返回假
{
    if(n1.hh!=n2.hh)
        return n1.hh>n2.hh;
    else if(n1.mm!=n2.mm)
        return n1.mm>n2.mm;
    else
        return n1.ss>n1.ss;
}

int main()
{
    //freopen("in.txt","r",stdin);

    string l,r;
    node left,right;
    left.hh=99,left.mm=99,left.ss=99;
    right.hh=-1,left.mm=-1,left.ss=-1;


    int k;
    cin>>k;
    while(k--)
    {
        string tid;
        node tnode1,tnode2;
        cin>>tid;
        scanf("%d:%d:%d %d:%d:%d",&tnode1.hh,&tnode1.mm,&tnode1.ss,&tnode2.hh,&tnode2.mm,&tnode2.ss);
        if(later(left,tnode1))//node1比left早?
        {
            l=tid;
            left=tnode1;
        }
        if(later(tnode2,right))//node2比right晚?
        {
            r=tid;
            right=tnode2;
        }
    }

    cout<<l<<' '<<r;


    return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值