九度:1022:游船出租

// 浙大2007机试
// 
// 题目:游船出租
// 考察:输入控制、四舍五入、Hash、统计
//
//
//
//
//
//
//
//
//
//
//
//




#include  <stdio.h>
#include  <cstring>
#include  <stdlib.h>
#include  <cctype>

#include  <iostream>
#include  <string>
#include  <algorithm>
#include  <map>
#include  <set>
#include  <vector>
#include  <stack>
#include  <queue>

#define SIZE 110

using namespace std;

struct Tnode{
	int hour;
	int minute;
};

struct Node{
	bool s;
	bool e;
	Tnode l;// 借船时间
	Tnode b;// 还船时间
};


//-----------Global-----
Node boat[SIZE];


//-----------Global-----


void Init()
{
	memset(boat, 0, sizeof(boat));
}

void First(int num)
{
	Tnode t;
	char c;
	scanf(" %c %d:%d", &c, &t.hour, &t.minute);//输入之前还有一个空格
	if(c == 'S')
	{
		boat[num].s = true;
		boat[num].l.hour = t.hour;
		boat[num].l.minute = t.minute;
	}
	else
	{
		boat[num].e = true;
		boat[num].b.hour = t.hour;
		boat[num].b.minute = t.minute;
	}
}


void Input()
{
	int num;
	Tnode t;
	char c;
	while( scanf("%d %c %d:%d", &num, &c, &t.hour, &t.minute) && num != 0)
	{
		if(c == 'S')
		{
			boat[num].s = true;
			boat[num].l.hour = t.hour;
			boat[num].l.minute = t.minute;
		}
		else
		{
			boat[num].e = true;
			boat[num].b.hour = t.hour;
			boat[num].b.minute = t.minute;
		}
	}//while: read date
}

//t2 - t1
int Subtract(Tnode t1, Tnode t2)
{
	int total=0;
	total = (t2.hour - t1.hour - 1) * 60 + 60 - t1.minute + t2.minute;
	return total;
}

void Deal()
{
	double totaltime=0.0;
	int cn=0; // recording times

	int i;
	for(i=1; i<=100; i++)
	{
		if(boat[i].s == true && boat[i].e == true)
		{
			cn++;
			totaltime += (double)Subtract(boat[i].l, boat[i].b);
		}// borrow & back
	}

	double avg = totaltime / cn ;
	int t = (int) (avg + 0.5);
	printf("%d %d\n", cn, t);
}

int main()
{

#ifdef ONLINE_JUDGE
#else
	freopen("E:\\in.txt", "r", stdin);
#endif


	int id;
	while(scanf("%d", &id)  && id != -1)
	{
		if(id == 0)
		{
			int c;
			Tnode t;
			scanf(" %c %d:%d", &c, &t.hour, &t.minute);//输入之前还有一个空格,读入数据,不处理
			printf("0 0\n");
			continue;
		}//第一个数据为0, 今天没人借船
		Init();
		First(id);
		Input();
		Deal();
	}//while

	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值