牛客网考研机试题集合:游船出租

考点:模拟

注意:

1.测试用例的问题:该题不太好

若:

1 S 10:00

1 S 12:00

该如何处理?(是认为1 S 12:00为无效数据,还是为最新的有效数据?)

若:

1 S 10:00

1 E 12:00

1 E 13:00

该如何处理?(正常认为1 E 13:00为无效数据)

题目没有说清楚。

2.平均租船时间是四舍五入,而是始终上取整?

3.可能同一辆船多次借还。

网友讨论的结果中该题的样例测试:这个题AC的代码,S的时候不考虑该船的状态,两次S直接按最新的更新信息,只要S过,连续几次E都是有效的,完全没考虑船可不可借可不可换的状态。

#include<bits/stdc++.h>
using namespace std;
const int MAXSIZE=101;

struct E {
	int start,end;
	int s,e;
	E() {
	}
	E(int start,int end,int s,int e):start(start),end(end),s(s),e(e) {
	}
} boat[101];

set<int> ids;
int main() {
	int id,h,min;
	int cnt=0,  sum=0;
	char ch;
	fill(boat,boat+101,E(0,0,0,0));
	while(scanf("%d",&id)!=EOF) {

		if(id==-1) {
			break;
		}
		getchar();
		scanf("%c",&ch);
		scanf("%d:%d",&h,&min);
		if(id==0) {
			if(cnt!=0) {
				cout<<cnt<<" "<<(int)(sum/(cnt*1.0)+0.5)<<endl;
			} else {
				cout<<"0 0"<<endl;
			}
			fill(boat,boat+101,E(0,0,0,0));
			continue;
		}
		int t=h*60+min;
		if(ch=='S') {
			boat[id].s=1;
			boat[id].start=t;
		} else {
			if(boat[id].s==1){
				cnt++;
				sum+=t-boat[id].start;
			}
		}
	}

	return 0;
}


 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值