PAT甲级1008水题飘过

题目分析:上去下来到达的时间和数量

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int k[105];
 5 
 6 int main(){
 7     int n;
 8     while(scanf("%d", &n) != EOF){
 9         int ans = 0;
10         int floor = 0;
11         ans += n*5;
12         for(int i = 1; i <= n; i++){
13             scanf("%d", &k[i]);
14             if(k[i] > floor){
15                 ans += (k[i] - floor) * 6;
16                 floor = k[i];
17             }
18             else if(k[i] < floor){
19                 ans += (floor - k[i]) * 4;
20                 floor = k[i];
21             }
22         } 
23         printf("%d\n", ans);
24     }
25     return 0;
26 } 

 

posted on 2019-10-09 16:17  白泽talk  阅读(111)  评论(0编辑  收藏  举报