1. 程式人生 > >1006 Sign In and Sign Out

1006 Sign In and Sign Out

isp style ios -c sed algorithm namespace 分享圖片 code

水題~

技術分享圖片
#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

1006 Sign In and Sign Out