电梯从0层开始,只需要用一个指针pre记录之前的位置,然后计算就行
#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n&&n)
{
int sum = 0,pre = 0;
sum += n*5;
for(int i=0,number;i<n;i++)
{
cin>>number;
if(pre>number) sum += (pre-number)*4;
else sum += (number-pre)*6;
pre = number;
}
cout<<sum<<endl;
}
}