【PAT甲级】1008 Elevator (20分)
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分)的更多相关文章
- PAT 甲级 1008 Elevator (20)(代码)
1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...
- PAT 甲级 1008 Elevator (20)(20 分)模拟水题
题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...
- 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 ...
- PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
- 1008 Elevator (20分)
1008 Elevator (20分) 题目: The highest building in our city has only one elevator. A request list is ma ...
- 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 ...
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...
随机推荐
- python中基本数据类型以及运算符
python中基本数据类型以及运算符的知识 一.与用户的交互以及python2与python的区别 1.1什么是与用户交互 用户交互就是人往计算机中input(输入数据),计算机print(输出结果) ...
- ubuntu 或centos 使用Docker搭建anaconda+python基本环境
ubuntu 16 使用Docker安装anacondaubuntu docker 安装centos docker 安装搜索可用镜像 docker search anaconda 拉取你中意的镜像 d ...
- mysql 安装(Linux、Ubuntu)
1.检查系统是否已经安装过mysql rpm -qa | grep mysql 若出现类似于以上的结果则表明系统已经安装过mysql,执行以下命令卸载 rpm -e --nodeps mysql-co ...
- Linux uevent分析、用户接收uevent以及mdev分析
关键词:uevent.netlink.ADD/REMOVE/CHANGE.uevent_helper.hotplug.usermode helper.mdev.mdev.conf等等. 本文从三方面了 ...
- navicat premium 12 破解,本人亲测有效,针对error on decrypt request code的解决方法
好,废话不多说,直接上步骤: 下载安装Navicat 由于本人信服官网的东西,所以Navicat premium12是在官网上边下载.下载地址:https://www.navicat.com.cn/p ...
- alipay sign error
阴影部分地址参数有问题: <PAY_COMPLETE_PAGE_URL><![CDATA[https://baoxian.itaiping.com/ae-console/remote ...
- java 内存溢出总结
堆 /** * jvm 参数: -Xms5m -Xmx5m -Xmn2m -XX:NewSize=1m * @author admin * */ public class HeapOutOfMemor ...
- HDU2899Strange fuction(二分/三分)
传送门 题目大意:求 F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100):的最小值 题解:求个导,二分导函数零点,就是原函数最小值所在的 ...
- 《大数据技术应用与原理》第二版-第三章分布式文件系统HDFS
3.1分布式文件 HDFS默认一个块的大小是64MB,与普通文件不同的是如果一个文件小于数据块的大小,它并不占用整个数据块的存储空间. 主节点又叫名称节点:另一个叫从节点又叫数据节点.名称节点负责文件 ...
- Ubuntu 修改默认编辑器
sudo update-alternatives --config editor