PTA1008 Elevator
问题描述:
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
Input Specification:
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
Output Specification:
For each test case, print the total time on a single line.
Sample Input:
3 2 3 1
Sample Output:
41
题目分析:
代码如下:
#include<iostream>
using namespace std;
const int maxx=101;
int a[maxx];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
int sum=6*a[0]+5*n;
for (int i = 1; i < n; i++)
{
if(a[i]>=a[i-1]) sum+=6*(a[i]-a[i-1]);
else sum+=4*(a[i-1]-a[i]);
}
cout<<sum<<endl;
return 0;
}
总结
基础的签到题