PAT1008

这道题也就是简单地模拟一下电梯运行状态,基本上是十分简单。

#include<iostream>
using namespace std;

int list[100];

int main(){
    int num=-1;
    int n;
    int count=0;
    while(cin>>n){
        if(num==-1)
            num=n;
        else{
            list[count]=n;
            count++;
            if(count==num)
                break;
        }
    }
    
    int time=0;
    int now=0;
    int target=0;
    for(int i=0;i!=num;++i){
        target=list[i];
        //up or down
        if(target>now)
            time+=(target-now)*6;
        if(target<now)
            time+=(now-target)*4;
        time+=5;
        now=target;
    }
    cout<<time;
    
    return 0;
}

 

posted on 2019-08-27 09:40  川川——叮叮咚咚  阅读(185)  评论(0编辑  收藏  举报