题目有坑,如果出现了两次借同一本书的操作,那么以后借的一次为开始时间。
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
int sta[1007];
int n;
char s[10];
int time[1007];
using namespace std;
int coun,ave;
int cal(int x,int y)
{
return x*60+y;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{ coun=ave=0;
memset(sta,0,sizeof sta);
memset(time,0,sizeof time);
while(1)
{
int x,a,b;
scanf("%d%s",&x,s);
scanf("%d:%d",&a,&b);
if(x==0)
break;
if(s[0]=='S')
{
sta[x]=1;
time[x]=cal(a,b);
}
else if(s[0]=='E'&&sta[x]==1)
{
sta[x]=0;
coun++;
ave+=cal(a,b)-time[x];
//puts("aaaa");
}
}
double tmp=(double)ave;
if(coun)
printf("%d %.0lf\n",coun,tmp/coun);
else
printf("0 0\n");
}
return 0;
}