题目1022:游船出租
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:4249
解决:1680
-
题目描述:
-
现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下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 <string> #include <cmath> using namespace std; typedef struct Boat { int flag;//判断是否借出,0表示未借出,1表示借出 int number;//船号 int start;//开始时间 int time;//持续时间 }Boat; int main() { int number;//船号 char key;//符号 int hour,minute;//借出时间 int count;//次数 double boattime;//总时间 Boat boat[105]; char ch,ch1; while(1) { cin>>number; if(number==-1) break; getchar(); count=0; boattime=0; while(number)//船号不为0时,可以一直借,但船号为0的时候一天结束 { //scanf(" %c %d:%d",&key,&hour,&minute); cin>>key>>hour>>ch>>minute; if(key=='S')//开始 { boat[number].number=number; boat[number].start=hour*60+minute; boat[number].flag=1; } else if(key=='E')//结束 { if(boat[number].flag==1) { boat[number].time=(hour*60+minute)-boat[number].start; ++count;//租船次数 boattime+=boat[number].time;//总时间 //cout<<boattime<<" ddd"<<endl; boat[number].flag=0; } } cin>>number; //cout<<"sss"<<endl; } cin>>key>>hour>>ch>>minute; if(count!=0) cout<<count<<" "<<(int)((boattime/count)+0.5)<<endl; else cout<<"0 0"<<endl; } return 0; }