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;
}


运行结果:

最新文章

  1. 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
  2. JDK source 之 ArrayList 需要注意事项
  3. JS(获得当前时间并且用2015-01-01格式表示)
  4. Android ant自动打包 crunch 报错
  5. [转]oracle EBS 基础100问
  6. UUID为36位
  7. jquery.validate.js 无法验证隐藏域
  8. unity3d在菜单栏,一键设置Player setting及自动打包并设置apk的存储位置
  9. 谈一谈Java中的Error和Exception
  10. handsontable 渲染实例
  11. UNIX环境高级编程——system V信号量
  12. innodb_flush_log_at_trx_commit与sync_binlog理解
  13. ISCC:Please give me username and password!
  14. JavaScript(JS)之Javascript对象DOM(三)
  15. January 04th, 2018 Week 01st Thursday
  16. android通过命令行安装sdk
  17. WebService和Http的POST和GET请求区别和示例
  18. 关于Python的集合set
  19. vue2.0使用动态组件实现tab切换效果(vue-cli)
  20. C语言函数參数传递原理

热门文章

  1. https连接
  2. python监控cpu 硬盘 内存
  3. Linux—挂载磁盘(云盘)
  4. 9. java API使用 - Scanner类
  5. NOI Linux vim配置文件
  6. docker修改系统时间总结
  7. git必知必会
  8. angular ng-bind-html异常Attempting to use an unsafe value in a safe context处理
  9. Java并发编程入门,看这一篇就够了
  10. 基于 HTML5 WebGL 构建智能城市 3D 场景