PAT (Advanced Level) 1008 Elevator (20 分)
发布日期:2021-06-29 12:22:22 浏览次数:2 分类:技术文章

本文共 386 字,大约阅读时间需要 1 分钟。

题目描述:

模拟,计算电梯运行总时间

分析:

逐个比较相邻的楼层,进行大小差值比较后计算时间

#include
using namespace std;int main(){
int n; cin >> n; int pre = 0, now; int sum = 0; while(cin >> now) {
if(now > pre) sum += 6 * (now - pre); else sum += 4 * (pre - now); sum += 5; pre = now; } cout << sum << endl; return 0;}

总结:

注意审题!注意第一个3是总数目,而不是楼层数!

转载地址:https://bridge-killer.blog.csdn.net/article/details/115430737 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:PAT (Advanced Level) 1009 Product of Polynomials (25 分)
下一篇:PAT (Advanced Level) 1006 Sign In and Sign Out (25 分)

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月25日 05时44分52秒