开一个数组即可解决,一次AC
- import java.util.Scanner;
- public class P1008 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int[] a = new int[100];
- while(n!=0){
- a[0]=n;
- for(int i=1;i<=n;i++) a[i]=sc.nextInt();
- int sum = a[1]*6+5;
- for(int j=1;j<n;j++){
- if(a[j+1]>a[j])
- sum+=(a[j+1]-a[j])*6+5;
- else
- sum+=(a[j]-a[j+1])*4+5;
- }
- System.out.println(sum);
- n = sc.nextInt();
- }
- }
- }