1006 Sign In and Sign Out

水题~

#include<iostream>
#include<algorithm>
#include<string.h>
#define maxn 25
using namespace std;
typedef long long ll;
char s[maxn],ttime[10];
int maxh=0,maxm=0,maxs=0;
int minh=23,minm=59,mins=59;
int hr,me,sd;
char lockid[maxn],unlockid[maxn];
int main()
{
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>s;
        cin>>ttime;
        hr=(ttime[0]-'0')*10+(ttime[1]-'0');
        me=(ttime[3]-'0')*10+(ttime[4]-'0');
        sd=(ttime[6]-'0')*10+(ttime[7]-'0');
        if(hr<minh)
        {
            minh=hr,minm=me,mins=sd;
            strcpy(unlockid,s);
        }
        else if(hr==minh)
        {
            if(me<minm)
            {
                minh=hr,minm=me,mins=sd;
                strcpy(unlockid,s);
            }
            else if(me==minm)
            {
                if(sd<mins)
                {
                    minh=hr,minm=me,mins=sd;
                    strcpy(unlockid,s);
                }
            }
        }
        cin>>ttime;
        hr=(ttime[0]-'0')*10+(ttime[1]-'0');
        me=(ttime[3]-'0')*10+(ttime[4]-'0');
        sd=(ttime[6]-'0')*10+(ttime[7]-'0');
        if(hr>maxh)
        {
            maxh=hr,maxm=me,maxs=sd;
            strcpy(lockid,s);
        }
        else if(hr==maxh)
        {
            if(me>maxm)
            {
                 maxh=hr,maxm=me,maxs=sd;
                strcpy(lockid,s);
            }
            else if(me==maxm)
            {
                if(sd>maxs)
                {
                     maxh=hr,maxm=me,maxs=sd;
                    strcpy(lockid,s);
                }
            }
        }

    }
    cout<<unlockid<<" "<<lockid<<endl;
}
View Code

 

posted on 2018-11-27 21:22  FTA_Macro  阅读(97)  评论(0编辑  收藏  举报

导航