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. TSPITR fails With RMAN-06553 (Doc ID 2078790.1)

    TSPITR fails With RMAN-06553 (Doc ID 2078790.1) APPLIES TO: Oracle Database - Enterprise Edition - V ...

  2. JAVA 高级特性枚举和泛型

    枚举: 语法:  public enum 枚举名 { 枚举值表(罗列所有值) }  例如:  public enum EnumTest{MON,TUE,WED.THU,FRI,SAT,SUN} 枚举操 ...

  3. ACM 基本输入

    单次输入 C语言 int a,b; scanf("%d %d",&a,&b); C++语言 int a,b; cin >> a >> b; ...

  4. Ubuntu 18.04 安装 python 的 redis 库

    安装 如果只是安装了 python2.x 或者 python3.x,直接安装即可,命令如下: pip install redis 如果是同时安装了 python2.x 和 python3.x 的,则需 ...

  5. @ConfigurationProperties(pref="")加载局部配置文件

    刚开始@ConfigurationProperties(文件名)直接在参数里加文件名,其实是配置前缀pref="前缀".加载局部配置文件是@PropertySource(value ...

  6. 机器学习--用PCA算法实现三维样本降到二维

    对于维数比较多的数据,首先需要做的事就是在尽量保证数据本质的前提下将数据中的维数降低.降维是一种数据集预处理技术,往往在数据应用在其他算法之前使用,它可以去除掉数据的一些冗余信息和噪声,使数据变得更加 ...

  7. centos7删除MariaDB怎么操作

    有时我们要在centos上安装一些组件,需要先把原来的数据库删除,比如MariaDB,不然就出现冲突错误,那么如何删除数据库呢?首先查询所安装的MariaDB组件: [root@localhost l ...

  8. Python连载52-SOCKET编程示例

    一.UDP编程 1.客户端Client:发起访问的一方. 2.服务器端 3.server段编程 (1)建立socket,socket是负责具体通信的一个实例 (2)绑定,为创建的socket指派固定的 ...

  9. React: 研究React的组件化

    一.简介大概 在以往的Web开发中,会把web页面所有的复杂控件作为一个单一的整体进行开发,由于控件之间需要进行通信,因此不同的组件之间的耦合度会很多,由于开发一个控件的时候要考虑到控件与控件之间的联 ...

  10. 1+X证书web前端开发中级对应课程分析

    官方QQ群 1+x 证书 Web 前端开发 JavaScript 专项练习 http://blog.zh66.club/index.php/archives/198/ 1+x 证书 Web 前端开发初 ...