PAT1008 Elevator

电梯上升一层6秒,下降一层4秒,每层停留5秒

Sample Input: 
3 2 3 1 
Sample Output: 
41 

 

 

 

 

 

#include <iostream>
using namespace std;

int main()
{
    int N;
    cin>>N;
    int current = 0;
    int total = 0;
    while (N--)
    {
        int a;
        cin>>a;
        if (a >= current)
        {
            total += (a - current) * 6  + 5;
            current = a;
        }
        else
        {
            total += (current - a) * 4 + 5;
            current = a;
        }
    }
    cout<<total;
    return 0;
}
 

你可能感兴趣的:(pat)