PAT 甲级 1008 Elevator (20 分)(Java)
题目
题意解读
数学题,只需要注意不需要回到0层即可;
解法
解法一
import java.util.Scanner;
public class Main_1008 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean dir;
int pre = 0;
int res = 0;
for (int i = 0; i < n; i++) {
int m = sc.nextInt();
dir = m > pre ? true : false;
if(dir){
res += (m-pre) * 6;
}else{
res += (pre-m) * 4;
}
res += 5;
pre = m;
}
System.out.println(res);
}
}