浙大PAT 1008题 1008. Elevator

来源:互联网 发布:js获取上下文 编辑:程序博客网 时间:2024/05/21 18:45
//the elevator may stay at the same floor several times.#include<stdio.h>int main(){  int i,n,last=0,now,total=0;  scanf("%d",&n);  for(i=0;i<n;i++){    scanf("%d",&now);    if(now>last){  total=(now-last)*6+5+total;  last=now;    }    else if(now<last){  total=(last-now)*4+5+total;  last=now;    }    else{  total=total+5; }  }   printf("%d\n",total);  return 0; }