1095 Cars on Campus (30 分)

1095 Cars on Campus (30 分)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e4+100;
struct car
{
    char id[10];
    int time;
    char status[10];

} all[maxn],valid[maxn];

int  num=0;
map<string,int>parktime;

int timecount(int h,int m,int s)
{
    return h*3600+m*60+s;
}

bool cmp(car a,car b)
{
    return a.time<b.time;
}
bool cmp1(car a,car b)
{
    if(strcmp(a.id,b.id)==0)
    {
        return a.time<b.time;
    }
    return strcmp(a.id,b.id)<0;
}

int main()
{
    int n,k,h,m,s;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
    {
        scanf("%s %d:%d:%d %s",all[i].id,&h,&m,&s,all[i].status);
        all[i].time=timecount(h,m,s);
    }
    sort(all,all+n,cmp1);
    int maxtime=-1;
    for(int i=0; i<n-1; i++)
    {
        if(!strcmp(all[i].id,all[i+1].id)&&!strcmp(all[i].status,"in")&&!strcmp(all[i+1].status,"out"))
        {
            valid[num++]=all[i];
            valid[num++]=all[i+1];

            int intime=all[i+1].time-all[i].time;
            if(parktime.count(all[i].id)==0)
            {
                parktime[all[i].id]=0;
            }
            parktime[all[i].id]+=intime;
            maxtime=max(maxtime,parktime[all[i].id]);
        }
    }

    sort(valid,valid+num,cmp);

    int now=0;
    int numcar=0;

    for(int i=0;i<k;i++)
    {
        scanf("%d:%d:%d",&h,&m,&s);
        int time=timecount(h,m,s);
        while(now<num&&valid[now].time<=time)
        {
            if(!strcmp(valid[now].status,"in"))
            {
                numcar++;
            }
            else numcar--;
            now++;
        }
        printf("%d\n",numcar);
    }
    map<string,int>::iterator it;
    for(it=parktime.begin();it!=parktime.end();it++)
    {
        if(it->second==maxtime)
        {
            printf("%s ",it->first.c_str());
        }
    }
    printf("%02d:%02d:%02d\n",maxtime/3600,maxtime%3600/60,maxtime%60);

}

上一篇:每日英语--Week14


下一篇:USTC English Club Note20171012