题意:
坐电梯,上一层楼需要6秒,下一层楼需要4秒,在每一层会停留5秒,电梯开始在0层,输入要去的各个层,输出所需要的时间
#include <iostream>
using namespace std;
int main()
{
int n;
int step[101] = {0};
while (true)
{
cin >> n;
if (!n)break;
int time = 0;
step[0] = 0;
for (int i = 1; i <= n; i++)
cin >> step[i];
for (int i = 1; i <= n; i++)
{
if(step[i] > step[i - 1])
{
time += 6 * (step[i] - step[i - 1]);
}
else
{
time += 4 * (step[i - 1] - step[i]);
}
}
time += n * 5;
cout << time << endl;
}
return 0;
}