Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at any specific time point, the number of cars parking on campus, and at the end of the day find the cars that have parked for the longest time period.

Input Specification:

Each input file contains one test case. Each case starts with two positive integers N (≤), the number of records, and K (≤) the number of queries. Then N lines follow, each gives a record in the format:

plate_number hh:mm:ss status

where plate_number is a string of 7 English capital letters or 1-digit numbers; hh:mm:ss represents the time point in a day by hour:minute:second, with the earliest time being 00:00:00 and the latest 23:59:59; and status is either in or out.

Note that all times will be within a single day. Each in record is paired with the chronologically next record for the same car provided it is an out record. Any in records that are not paired with an out record are ignored, as are out records not paired with an in record. It is guaranteed that at least one car is well paired in the input, and no car is both in and out at the same moment. Times are recorded using a 24-hour clock.

Then K lines of queries follow, each gives a time point in the format hh:mm:ss. Note: the queries are given in accendingorder of the times.

Output Specification:

For each query, output in a line the total number of cars parking on campus. The last line of output is supposed to give the plate number of the car that has parked for the longest time period, and the corresponding time length. If such a car is not unique, then output all of their plate numbers in a line in alphabetical order, separated by a space.

Sample Input:

16 7
JH007BD 18:00:01 in
ZD00001 11:30:08 out
DB8888A 13:00:00 out
ZA3Q625 23:59:50 out
ZA133CH 10:23:00 in
ZD00001 04:09:59 in
JH007BD 05:09:59 in
ZA3Q625 11:42:01 out
JH007BD 05:10:33 in
ZA3Q625 06:30:50 in
JH007BD 12:23:42 out
ZA3Q625 23:55:00 in
JH007BD 12:24:23 out
ZA133CH 17:11:22 out
JH007BD 18:07:01 out
DB8888A 06:30:50 in
05:10:00
06:30:50
11:00:00
12:23:42
14:00:00
18:00:00
23:59:00

Sample Output:

1
4
5
2
1
0
1
JH007BD ZD00001 07:20:09
注意点:1.查询时 now 必须放在外面不然会重复循环导致超时!!!
    2.清空cout缓存用cout<<flush;否则使用ios::sync_with_stdio(false);
cin.tie(0)时不与printf兼容,可能输出顺序错误。
 #include<bits/stdc++.h>
using namespace std; const int maxn=; struct Record{
string carId;
int hh;
int mm;
int ss;
int time;
string status;
int flag;
}rec[maxn],valid[maxn]; int n,k; map<string,int> parkTime; int num=;
int maxTime=-; bool cmp1(Record a,Record b){
if(a.carId!=b.carId)
return a.carId<b.carId;
else
return a.time<b.time;
} bool cmp2(Record a,Record b){ return a.time<b.time; } int main(){ ios::sync_with_stdio(false);
cin.tie(); cin>>n>>k; // scanf("%d%d",&n,&k); char c;
Record temp; for(int i=;i<n;i++){
cin>>temp.carId>>temp.hh>>c>>temp.mm>>c>>temp.ss>>temp.status; //char str1[100];
//char str2[100];
//scanf("%s %d:%d:%d %s",&str1[0],&temp.hh,&temp.mm,&temp.ss,&str2[0]);
//temp.carId=str1;
//temp.status=str2; temp.time=temp.hh*+temp.mm*+temp.ss; if(temp.status=="in")
temp.flag=;
else
temp.flag=; rec[i]=temp;
} sort(rec,rec+n,cmp1); for(int i=;i<n-;i++){
if(rec[i].carId==rec[i+].carId&&
rec[i].flag==&&rec[i+].flag==){
valid[num++]=rec[i];
valid[num++]=rec[i+]; string carId=rec[i].carId; if(parkTime.count(carId)==){
parkTime[carId]=;
} parkTime[carId]+=(rec[i+].time-rec[i].time); maxTime=max(maxTime,parkTime[carId]); }
} sort(valid,valid+num,cmp2); int now=,nowCar=; //now必须放外面 for(int i=;i<k;i++){
int hh,mm,ss;
char c; cin>>hh>>c>>mm>>c>>ss; //scanf("%d:%d:%d",&hh,&mm,&ss); int queryTime=hh*+mm*+ss; while(now<num&&valid[now].time<=queryTime){
if(valid[now].flag==) nowCar++;
else nowCar--; now++; } cout<<nowCar<<endl; //printf("%d\n",nowCar); } for(map<string,int>::iterator it = parkTime.begin(); it != parkTime.end();it++){
if(it->second==maxTime)
{
cout<<it->first<<" "; // printf("%s ",it->first.c_str());
}
} cout<<flush; //清空cout缓存 //cout<<maxTime<<" "<<parkTime["JH007BD"]<<" "<<parkTime["ZD00001"]<<endl; printf("%02d:%02d:%02d\n",maxTime/,(maxTime/)%,maxTime%); return ;
}

  

最新文章

  1. 使用 jsoup 对 HTML 文档进行解析和操作
  2. STM32与FreeRTOS实现低功耗
  3. Error: Could not find or load main class test.EditFile
  4. Android瀑布流照片墙实现,体验不规则排列的美感
  5. 2015年第3本(英文第2本):Daughter of Deceit
  6. 一段linux shell 代码涉及for循环和if esle
  7. winform下载网页源码
  8. 关于webApi302跳转的问题
  9. 新到的Mac配置Java开发环境
  10. SpringMVC通过实体类返回json格式的字符串,并在前端显示
  11. HashiCorp Vault介绍
  12. 快速入门vue-cli配置
  13. else语句的搭配
  14. django csrf token添加
  15. 二、Docker部署应用
  16. linux 配置sendmail支持php mail 函数
  17. unigui验证微信服务器的有效性
  18. jquery获取系统当前时间
  19. 洛谷P2444 病毒 [POI2000] AC自动机
  20. C语言基础:初级指针 分类: iOS学习 c语言基础 2015-06-10 21:50 30人阅读 评论(0) 收藏

热门文章

  1. 听说这个FFT跑得巨jb快
  2. linux python3 venv 虚拟环境报错 [-Im&#39;, &#39;ensurepip&#39;, &#39;--upgrade&#39;, &#39;--default-pip&#39;]&#39; returned non-zero exit status 2.
  3. layui多图上传
  4. python excel单元格及样式
  5. 你真的懂return吗?
  6. tensorflow 训练最后预测结果为一个定值,可能的原因
  7. php连接mysql遇到的问题: (HY000/1130) 和 [caching_sha2_password]
  8. Linux下Qt调用共享库文件.so
  9. Effective C++之条款2:尽量以const enum inline替换 #define
  10. Eclipse规范注释及注释文档的生成