Problem Link:http://139.129.36.234/problem.php?id=1208
1208: 游船出租
时间限制: 1 Sec 内存限制: 32 MB提交: 2 解决: 2
[ 提交][ 状态][ 讨论版]
题目描述
现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下S键,系统开始计时;当游客还船时,管理员输入船号并按下E键,系统结束计时。船号为不超过100的正整数。当管理员将0作为船号输入时,表示一天租船工作结束,系统应输出当天的游客租船次数和平均租船时间。
注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有租船没有还船,或者只有还船没有租船的纪录,系统应能自动忽略这种无效纪录。
注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有租船没有还船,或者只有还船没有租船的纪录,系统应能自动忽略这种无效纪录。
输入
测试输入包含若干测试用例,每个测试用例为一整天的租船纪录,格式为:
船号(1~100) 键值(S或E) 发生时间(小时:分钟)
每一天的纪录保证按时间递增的顺序给出。当读到船号为-1时,全部输入结束,相应的结果不要输出。
船号(1~100) 键值(S或E) 发生时间(小时:分钟)
每一天的纪录保证按时间递增的顺序给出。当读到船号为-1时,全部输入结束,相应的结果不要输出。
输出
对每个测试用例输出1行,即当天的游客租船次数和平均租船时间(以分钟为单位的精确到个位的整数时间)。
样例输入
1 S 08:10
2 S 08:35
1 E 10:00
2 E 13:16
0 S 17:00
0 S 17:00
3 E 08:10
1 S 08:20
2 S 09:00
1 E 09:20
0 E 17:00
-1
样例输出
2 196
0 0
1 60
提示
来源
AC code:
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<math.h>
#include<string.h>
#include<queue>
#include<vector>
#include<set>
#define LL long long
#define exp 1e-9
#define MAXN 1000010
using namespace std;
int sum,cnt,num,h,m;
char ch;
int mark[111],sth[111],stm[111];
int jishi(int h1,int m1,int h2,int m2)
{
int sum=0;
if(h1<h2)
{
sum+=60-m1;
h1++;
}
sum+=(h2-h1)*60+m2;
return sum;
}
int main()
{
// freopen("D:\\in.txt","r",stdin);
memset(mark,0,sizeof(mark));
sum=cnt=0;
while(scanf("%d",&num)!=EOF)
{
if(num==-1) break;
if(num==0)
{
if(cnt==0) printf("0 0\n");
else
printf("%d %.0lf\n",cnt,sum*1.0/cnt);
memset(mark,0,sizeof(mark));
sum=cnt=0;
}
scanf(" %c %d:%d\n",&ch,&h,&m);
if(ch=='S')
{
mark[num]=1;
sth[num]=h;
stm[num]=m;
}
else if(ch=='E')
{
if(mark[num]==1)
{
cnt++;
sum+=jishi(sth[num],stm[num],h,m);
// printf("%d:%d\n",num,jishi(sth[num],stm[num],h,m));
mark[num]=0;
}
}
}
return 0;
}