首页 > 其他 > 详细

PAT1008

时间:2019-08-27 10:23:37      阅读:50      评论:0      收藏:0      [点我收藏+]

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

#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;
}

 

PAT1008

原文:https://www.cnblogs.com/chuan-chuan/p/11416390.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!