// 浙大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;
}
九度:1022:游船出租
最新推荐文章于 2017-03-13 09:50:19 发布