Description
The 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.
Input
There 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.
Output
Print the total time, on a, on a, a, single, and test case.
Sample Input
1 23 2) 3 10
Sample Output
1741
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;structdangchi{Charstr[ -]; intsum;};intMain () {#ifdef cdzsc_offline freopen ("In.txt","R", stdin);#endif intn,a,b,sum; while(SCANF ("%d", &n) &&n!=0) {b=0, sum=0; while(n--) {scanf ("%d",&a); if(a>b) {sum+ = (A-B) *6+5; b=A; } Else if(a<b) {sum+ = (b-a) *4+5; b=A; } Else{sum+=5; }} printf ("%d\n", sum); } return 0;}
View Code
Cdzsc_2015 new Winter Holiday (1)--Basic B