Description
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
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed. OutputPrint the total time on a single line for each test case. Sample Input1 23 2 3 10 Sample Output1741题目意思:上楼每层需要6秒,下楼每层需要4秒,在到达的楼层还要停留5秒
1 #include2 int main() 3 { 4 int n,i,count,f[100]; 5 while(scanf("%d",&n)!=EOF) 6 { 7 if(n==0) 8 break; 9 count=0;10 f[0]=0;11 for(i=1; i<=n; i++)12 {13 scanf("%d",&f[i]);14 if(f[i]>f[i-1])15 count=count+(f[i]-f[i-1])*6+5;16 else17 count=count+(f[i-1]-f[i])*4+5;18 }19 printf("%d\n",count);20 }21 return 0;22 }
明明是一道水题,可我还是看错意思了,以为在每一层都要停留,该死!