很简单电梯题目水题 不会的话
参考discuss 重复的楼层要增加时间

#include<cstdlib>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    int n;
    int i,j;
    int last_level = 0;
    int all_evel[110]={0};
    int sum_time = 0;
    while(scanf("%d",&n))
    {
        last_level = 0;
        sum_time = 0;
        memset(all_evel,0,sizeof(int)*110);
        if(n == 0)
            break;
        for(i = 0;i< n ;i++)
        {
            cin>>all_evel[i];
        }
        for(j=0;j<n;j++)
        {
            if(all_evel[j]>last_level)
            {
                sum_time+=(all_evel[j]-last_level)*6+5;
                last_level = all_evel[j];
            }
            else if(all_evel[j]==last_level)
            {
                sum_time+=5;
                last_level = all_evel[j];
            }
            else
            {
                sum_time+=abs(all_evel[j]-last_level)*4+5;
                last_level = all_evel[j];
            }
        }
        printf("%d\n",sum_time);
    }
}
posted on 2017-06-06 15:04  HDU李少帅  阅读(131)  评论(0编辑  收藏  举报