游客 Signup | Login
中文 | En

1642 - 游船出租

现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下S键,系统开始计时;当游客还船时,管理员输入船号并按下E键,系统结束计时。船号为不超过100的正整数。当管理员将0作为船号输入时,表示一天租船工作结束,系统应输出当天的游客租船次数和平均租船时间。

注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有租船没有还船,或者只有还船没有租船的纪录,系统应能自动忽略这种无效纪录。

Input

测试输入包含若干测试用例,每个测试用例为一整天的租船纪录,格式为:

船号(1~100) 键值(S或E) 发生时间(小时:分钟)
每一天的纪录保证按时间递增的顺序给出。当读到船号为-1时,全部输入结束,相应的结果不要输出。

Output

对每个测试用例输出1行,即当天的游客租船次数和平均租船时间(以分钟为单位的精确到个位的整数时间)。

Examples

Input

1 S 07:10
2 S 09:35
1 E 10:00
2 E 12:50
0 S 18:00
0 S 07:00
-1

Output

2 183
0 0

Hint

a[k]表示船号为k的被借出的时间,若k未被借出,则值为-1。接着按题目要求模拟操作即可。

Solution C

#include <stdio.h>
#include <string.h>

typedef struct
{
	int no;
	int h,m;
	int tag;
}Node;

Node arry[105];


int main()
{
	int no,h,m;
	char op;
	int times,avetime;
	memset(arry,0,sizeof(arry));
	times = 0 , avetime = 0;
	while( scanf( "%d" , &no ) && no != -1)
	{
		scanf(" %c %d:%d" , &op , &h , &m );
		if( no == 0 )  //表示当前这组数据输入完毕,准备输出
		{
			if( times == 0 ) printf( "0 0\n" );  //如果输入次数为0的时候
			else
			{
                        //四舍五入
				if( avetime*1.0/times - avetime/times >= 0.5 )   avetime = avetime / times + 1;
				else    avetime = avetime/times;
				printf( "%d %d\n" , times , avetime );
			}
                  //清零,准备记录下一组数据
			memset(arry,0,sizeof(arry));
			times = 0 , avetime = 0;
		}
		else
		{
			if( op == 'S' && arry[no].tag == 0 )  //开始op == 'S',并且以前没有开始过arry[no].tag == 0
			{
				arry[no].h = h , arry[no].m = m;
				arry[no].tag = 1;
			}
			else if( op == 'E' && arry[no].tag == 1 ) //结束op == 'E',并且开始过arry[no].tag == 1
			{
				int time = (h-arry[no].h)*60 - arry[no].m + m;
				avetime += time;
				times++;
				arry[no].tag = 0;
			}
		}

	}
	return 1;
}

Solution C++

#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    while (true) {
        int k;
        scanf("%d", &k);
        if (-1 == k) break;
        char ss[10];
        int h, m, a[105], cnt = 0;
        double sum = 0;
        scanf("%s %d:%d", ss, &h, &m);
        fill(a, a + 105, -1);
        while (k > 0) {
            int x = h * 60 + m;
            if (ss[0] == 'S') {
                if (a[k] == -1)
                    a[k] = x;
            } else {
                if (a[k] != -1) {
                    sum += x - a[k];
                    ++cnt;
                    a[k] = -1;
                }
            }
            scanf("%d %s %d:%d", &k, ss, &h, &m);
        }
        if (0 == cnt)
            puts("0 0");
        else
            printf("%d %.0f\n", cnt, sum / cnt + 1e-8);
    }
    return 0;
}

Hint

a[k]表示船号为k的被借出的时间,若k未被借出,则值为-1。接着按题目要求模拟操作即可。

Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题