题解 | #游船出租#
游船出租
https://ac.nowcoder.com/practice/50fc5c0009cf4083bca5fbedcb4b6dc0
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <utility>
//如果非要写的话
//这个评论区大佬解释真正的规则
评测案例有问题,与题目描述不符
在评测案例里,如果一艘船租了,还了,然后又还了一次,相当于租还了2次(正确的应该是租还一次)。
比如:
1 S 00:00
1 E 01:00
1 E 02:00
0 S 00:00
-1
结果为
2 90
//就是只要船租过一次,就可以一直还,不用考虑船的状态,坑的一
using namespace std;
int tominute(int a, int b) {
return a * 60 + b;
}
int main() {
int a, c, d;
char b;
map<int, int> m;
// memset(m, pair<int, int>(0,0), sizeof(m));
map<int, int> z; //状态0空闲1忙碌
int sum = 0, count = 0;
while (scanf("%d %c %d:%d", &a, &b, &c, &d)) { // 注意 while 处理多个 case
// if (a == -1)
// break;
if (a == 0) {
//结算
if (count == 0) {
cout << 0 << " " << 0 << endl;
} else {
// cout << count << " " << sum << endl;
cout << count << " " << int((float)sum / (float)count + 0.5) << endl;
}
break;
} else {
// cout << a << " " << b << " " << c << " " << d << endl;
if ( b == 'S') { //空闲
z[a] = 1;
m[a] = tominute(c, d);
}
if ( z[a] == 1 && b == 'E') {
count++;
sum += (tominute(c, d) - m[a] );
}
}
}
}
// 64 位输出请用 printf("%lld")
睿联技术公司福利 62人发布
查看8道真题和解析
