Home » Java » Zhongkai ACM 1020: Elevator [Java]

Zhongkai ACM 1020: Elevator [Java]

package acm;
Import java.util.Scanner;
Public class {elevator
Public static void main (String args[]) {
Scanner input = new Scanner (System.in);
While ((input.hasNext)) {
Int = input.nextInt (a);
If (a = = 0) break;
Int d = 0;
Int sum = 0;
If (a! = 0 & & A < 100) {
For (int c = 0; C < A; C + +) {
Int = input.nextInt (B);
If (b = D)
Sum = sum + *6 (B - D) + 5; / / lift up
If (b < d)
Sum = sum + *4 (D - b) + 5; / / lift down
D = B; / / assign B to D, compared with the next number, so the cycle
}
System.out.println (sum);
}
}
}
}


Problem description


The tallest building in the city has only one elevator. An elevator lifting task table consists of N positive integers, these numbers represent the number of floors.
stay in the given order of the elevator
Lift up a layer takes 6 seconds, down a layer of spent 4 seconds, and stay take 5 seconds to.

For each task you want to complete the table, calculate the total time spent all lifting tasks. First, the elevator on the zeroth floor, and finally complete the task when the elevator does not have to return to the 0 layer.


Input format


There are many groups of test sample. Each test case contains a positive integer N, then N is a positive integer >.In the input, all the numbers are less than 100. when N=0, the input end >.


output


For each group of test sample in a row total output time.


sample input


>123231

0


sample output


>1741

Latest