Problem DescriptionThe Highest building in We City have only one elevator. A request list is made to with N positive numbers. The numbers denote at which floors the elevator would stop, in specified order. It costs 6 seconds to move the elevator-one floor, and 4 seconds to move-down-one floor. The elevator would stay for 5 seconds on each stop.
For a given request list, you is 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 having to return to the ground floor when the requests was Fu Lfilled. Inputthere is multiple test cases. Each case contains a positive an integer n, followed by N positive numbers. All the numbers in the input is less than 100. A test Case with N = 0 denotes the end of input. This test is a not-to-be processed. Outputprint the total time, on a, on a, a, and each test case. Sample INPUT1 2 3 Sample Output1741
1#include <stdio.h>/*a water problem, a second kill*/2 intMain ()3 {4 intN;5 while(SCANF ("%d", &n) = =1)6 {7 if(n==0)8 Break;9 inta[101],i,j,time=0, K;Tena[0]=0; One for(i=1; i<=n;i++) Ascanf"%d",&a[i]); - for(i=1; i<=n;i++) -time+= (a[i]-a[i-1]>0? (a[i]-a[i-1])*6:(a[i-1]-a[i]) *4)+5; theprintf"%d\n", time); - } -}
Elevator (hdoj 1008)