九度 1022 游船出租

题目1022:游船出租

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:1431

解决:588

题目描述:
    现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下S键,系统开始计时;当游客还船时,管理员输入船号并按下E键,系统结束计时。船号为不超过100的正整数。当管理员将0作为船号输入时,表示一天租船工作结束,系统应输出当天的游客租船次数和平均租船时间。
    注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有租船没有还船,或者只有还船没有租船的纪录,系统应能自动忽略这种无效纪录。
输入:

    测试输入包含若干测试用例,每个测试用例为一整天的租船纪录,格式为:
    船号(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
//九度数据严格 需要四舍五入
#include <iostream>
#include <list>
#include<cmath>
using namespace std;
struct Record {
    int id;
    char key;
    int time;
};
bool returnboat(list<Record> RentRecord,Record rec,int &sumtime,int &count);
int main()
{
    int count=0,sumtime=0,id,hour,minute;
    char ch;
    Record rec;
    list<Record> RentRecord;
    while(cin>>id && id!=-1) {
        //下面这两句必须放在这里 不然只能执行一次
        cin>>rec.key>>hour>>ch>>minute;
        rec.time=hour*60+minute;
        if(id==0) {
            if(count==0)
                cout<<0<<" "<<0<<endl;
            else
                cout<<count<<" "<<int(double(sumtime*1.0/count)+0.5)<<endl;
            count=sumtime=0;
            RentRecord.clear();
            continue;
        } else {
            rec.id=id;
            if(rec.key=='S')
                RentRecord.push_back(rec);
            else if(rec.key=='E') {
                returnboat(RentRecord,rec,sumtime,count);
            }
        }
    }
    return 0;
}
bool returnboat(list<Record> RentRecord,Record rec,int &sumtime,int &count)
{
    list<Record>::iterator iter;
    for(iter=RentRecord.begin(); iter!=RentRecord.end(); iter++) {
        if((*iter).id==rec.id && (*iter).key=='S' ) {
            sumtime+=(rec.time-(*iter).time);
            count++;//成功租船一次
            RentRecord.erase(iter);//删除记录
            return true;
        }
    }
}
/**************************************************************
    Problem: 1022
    User: windzhu
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1512 kb
****************************************************************/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值