1008 Elevator

题目:

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


注意:

  • 这句句子一开始做题没看懂。


    翻译:每个例子包含一个正整数N,后面跟着N个正整数。

    (第一个数是数字的个数,第二个数串才是输入样例)

① Each case contains a positive integer N, followed by N positive numbers.


  • 每到达一个目标层次,停留5秒。包括最后一个目标层数

    The elevator will stay for 5 seconds at each stop.


  • (在这题目中没有出现,只是突然想到的)


    Java中有方法length()可以直接得到数组的长度;

    在C++中,字符串可以用strlen()得到长度,其他类型的数组用sizeof(数组名)/sizeof(数组的任一元素)




代码:

#include<iostream>
using namespace std; int main() {
int n; //N numbers
cin>>n; int time=0;//time time
int curr=0;//current floor
int number;
for(int i=0; i<n; i++) {
cin>>number; if(curr<number) { //go up
time+=(number-curr)*6+5;
} else if(curr>number) {//go down
time+=(curr-number)*4+5;
} else { //same floor
time+=5;//stay
continue;
}
curr=number; } cout<<time<<endl; return 0;
}


运行结果:

【PAT甲级】1008 Elevator (20分)的更多相关文章

  1. PAT 甲级 1008 Elevator (20)(代码)

    1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...

  2. PAT 甲级 1008 Elevator (20)(20 分)模拟水题

    题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...

  3. PAT Advanced 1008 Elevator (20 分)

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

  4. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  5. 1008 Elevator (20分)

    1008 Elevator (20分) 题目: The highest building in our city has only one elevator. A request list is ma ...

  6. PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  7. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  8. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  9. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

随机推荐

  1. 微信小程序根据生日获取年龄

    // 根据出生日期计算年龄周岁 传参格式为1996-06-08 // 根据出生日期计算年龄周岁 传参格式为1996-06-08 function getAge(strBirthday) { var r ...

  2. bay——巡检RAC日志.txt

    -查找超过800M大小文件,并显示查找出来文件的具体大小,可以使用下面命令 find . -type f -size +400M -print0 | xargs -0 du -h --查看当前目录下每 ...

  3. layui 获取radio单选框选中的值

    Layui 获取 radio的值,layui判断radio选中的单选值 layui form 表单获取radio选中的值 首先准备两个radio <input type="radio& ...

  4. [日常] windows下使用vscode配合xebug调试php脚本

    windows下使用vscode配合xebug调试php脚本 要下载有php_xebug.dll扩展的版本,最新版可能没有这个扩展,php7.3应该是有的,php7.3.4好像没有默认是不加载这个扩展 ...

  5. python3 邮件方式发送测试报告

    以邮件方式发送测试报告 import smtplib from email.mime.text import MIMEText class SendEmail: """邮 ...

  6. 利用Mac的功能键|如何在Mac上使用F键

    Mac键盘的顶部是一组按键,这些按键的特征是F后跟1-12数字.这些键称为Mac功能键,使您可以通过按几个键来更改某些设置并快速访问Mac功能. 如果您是Mac的所有者,是时候学习这些键各自可以做什么 ...

  7. javascript中优雅的处理async和await异常

    let handler = async function(needErr) { return new Promise((resolve, reject) => { if (needErr) { ...

  8. 转载-SpringBoot结合线程池解决多线程问题实录;以及自己的总结

    原文地址:https://blog.csdn.net/GFJ0814/article/details/92422245 看看这篇文章(继续学习):https://www.jianshu.com/p/3 ...

  9. pytest框架之pytest-html报告生成

    一.关于安装 pytest-html属于pytest的一个插件,使用它需要先安装 pip install pytest-html pytest可以生成多种样式的结果: 生成JunitXML格式的测试报 ...

  10. Python 如何操作微信

    1.给文件传输助手发一条消息 import itchat itchat.auto_login(enableCmdQR=True) # 这里需要你人工手机扫码登录 itchat.send('Hello, ...