【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 ...
随机推荐
- could not launch process: debugserver or lldb-server not found: install XCode's command line tools or lldb-server
0x00 事件 VS 调试 go 的时候,发生了这个错误,导致无法调试: could not launch process: debugserver or lldb-server not found: ...
- 数据结构笔记2(c++)_跨函数使用内存的问题
预备知识 1.所有的指针变量只占4个子节 用第一个字节的地址表示整个变量的地址 //1.cpp 所有的指针变量只占4个子节 用第一个字节的地址表示整个变量的地址 # include <stdi ...
- 预览本地图片原生js
<!-- 样似总结: 用a标签代替file,做文件上传. 将file进行绝对定位,透明度设置为0:宽度为“上传图片”的宽度,超出部分隐藏. 这样做是为了将file隐藏起来.用a标签代替file ...
- 一、itk在VS2019上面的安装 和例子(HelloWorld)运行
一.Itk简介 vtk是专门用于医疗图像处理的函数库,类似opencv. 这篇博客主要是讲解安装vtk之后的例子的运行,即如何构建自己的第一个ITK例子 二.Itk安装 Itk安装参考这篇博客: ht ...
- class与class的继承
class Point{ constructor(x,y){ this.x = x; this.y = y; } toString(){ return '(' + this.x + ',' + thi ...
- idea tomcat debug不能启动的问题
显示:Connected to the target VM, address: '127.0.0.1:54692', transport: 'socket' 其实原因是没调整好面板.晕 ...
- [LeetCode] 42. Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- vscode源码分析【二】程序的启动逻辑,第一个窗口是如何创建的
上一篇文章:https://www.cnblogs.com/liulun/ (小广告:我做的开源免费的,个人知识管理及自媒体营销工具“想学吗”:https://github.com/xland/xia ...
- angularjs事件通信$on,$emit,$broadcast详解
公司项目开发用的是angularjs,关于事件通讯一直用的是EventBus,直到上周写一个小组件懒得引用EventBus时,想到用angularjs自带的事件通信时,结果很尴尬的忘记原生方法单词怎么 ...
- pyqt添加启动等待界面
一.实验环境 1.Windows7x64_SP1 2.anaconda3.7 + python3.7(anaconda集成,不需单独安装) 3.pyinstaller3.5 #使用pyinstalle ...