1008 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.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
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
//分析:要求列表由N个正整数组成,电梯会停在这些数字的层数
//电梯上升一层用6s,下降一层用4s,花5s停一次
//求完成列表要求所用的总时间,电梯刚开始在第0层,完成列表后不需要回到底楼
#include <stdio.h>
int main(){
int n,pre=0,aft;
int t=0;
scanf("%d",&n);
while(n--){
scanf("%d",&aft);
if(aft>pre)
t+=(aft-pre)*6+5;
else
t+=(pre-aft)*4+5;
pre=aft;
}
printf("%d",t);
}
标签:pre,floor,list,elevator,numbers,Elevator,1008,aft 来源: https://blog.csdn.net/yqajsj/article/details/87907459