題意:給一個數n,後跟着n個數,代表電梯要到的層數,如果是上升,則每層花費6分鐘,下降每層劃分4分鐘,停着話費5分鐘,求電梯總共花費多少時間。
#include <iostream>
using namespace std;
void main()
{
int n, m, t, total;
while (cin >> n && n != 0)
{
m = 0;
total = 0;
while (n--)
{
t = m;
cin >> m;
total += (m - t > 0 ? 6 * (m - t) : 4 * (t - m)) + 5;
}
cout << total << endl;
}
}