zoukankan      html  css  js  c++  java
  • PAT 1008 Elevator (20)

    The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

    For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

    Input Specification:

    Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.

    Output Specification:

    For each test case, print the total time on a single line.

    Sample Input:

    3 2 3 1
    

    Sample Output:

    41

    题目大意:一栋大楼里面只有一部电梯,初始在0楼,上升一楼要6秒,下降一楼要4秒, 每一楼要停留5秒,现在给出一串电梯停靠的楼层,计算按照顺序停靠完,需要多少时间
    输入:第一个数字是需要停靠的次数,后面跟着停靠的楼层
    last:上一次停靠的楼层
    now:这一次停靠的楼层
    ans: 记录所需时间
     1 #include<iostream>
     2 using namespace std;
     3 int main(){
     4   int n, last = 0, now, ans = 0;
     5   cin>>n;
     6   for(int i=0; i<n; i++){
     7     cin>>now;
     8     if(now>last) ans += (now-last)*6;
     9     else ans += (last-now)*4;
    10     ans += 5;
    11     last = now;
    12   }
    13   cout<<ans;
    14 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    JavaScript 相等(==)与全等(===)操作符
    JavaScript 判断空对象、空数组的方法
    JavaScript中的深拷贝与浅拷贝
    JS trim去除字符串收尾指定字符
    Django+Markdown+Pygments 支持Markdown 实现代码高亮
    crontab 定时服务
    程序员如何修复婚姻的bug
    向Mysql 中插入汉字(Emoji)出现 Incorrect string value
    根据html页面id寻找对应的Js文件
    Django Pagination
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9131399.html
Copyright © 2011-2022 走看看