#include<iostream>
using namespace std;
int main()
{
int n;
int cur = 0;
int floor;
int total = 0;
int tmp;
cin>>n;
for(int i=0; i<n; ++i)
{
cin>>floor;
tmp = floor - cur;
total += (tmp > 0 ? tmp * 6 : tmp * (-4));
cur = floor;
}
total += n * 5;
cout<<total<<endl;
return 0;
}PAT 1008 Elevator
最新推荐文章于 2021-08-18 12:42:21 发布
本文详细解析了一段使用C++语言编写的代码片段,该代码用于根据输入的楼层进行计数,并通过特定的数学公式计算累计总和。代码中涉及循环、条件判断、变量初始化与更新等基本编程概念,旨在展示如何通过编程解决实际问题。
1667

被折叠的 条评论
为什么被折叠?



