PAT甲级练习1008. Elevator (20)
来源:互联网 发布:mac版单机游戏 编辑:程序博客网 时间:2024/04/29 07:20
1008. Elevator (20)
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 1Sample Output:
41
import java.util.ArrayList;import java.util.Scanner;public class Main {public static void main(String[] args) {ArrayList<Integer> aGuest = new ArrayList<Integer>();int iGuest = 0;int iLastGuest = 0;int iTime = 0;Scanner s = new Scanner(System.in);int n = s.nextInt();for(int i=0; i<n; i++){aGuest.add(s.nextInt());}for(int i=0; i<aGuest.size(); i++){iGuest = aGuest.get(i);if(iGuest > iLastGuest){iTime += (iGuest - iLastGuest) * 6 + 5;iLastGuest = iGuest;}else{iTime += (iLastGuest - iGuest) * 4 + 5;iLastGuest = iGuest;}}System.out.printf("%d", iTime);}}
- PAT甲级练习1008. Elevator (20)
- 【PAT甲级】1008. Elevator (20)
- PAT甲级1008. Elevator (20)
- PAT甲级1008. Elevator (20)
- pat甲级1008. Elevator (20)
- PAT甲级 1008. Elevator (20)
- PAT甲级 1008. Elevator(20)
- PAT 甲级 1008. Elevator (20)
- PAT甲级1008. Elevator(20)
- PAT甲级1008. Elevator (20)
- PAT 甲级 1008. Elevator
- [PAT-甲级]1008.Elevator
- PAT甲级1008. Elevator
- PAT 甲级 1008. Elevator
- 1008. Elevator (20)-PAT甲级真题
- 【PAT甲级】【C++】1008. Elevator (20)
- PAT TEST甲级1008. Elevator (20)
- PAT - 甲级 - 1008. Elevator (20)1008. Elevator (20)
- TI_BLE软件开发者指导5-HCI
- C语言深度解剖之——for循环优化
- NoSQL 在腾讯应用实践
- HBase 常用Shell命令
- Hadoop 2.x HDFS和YARN的启动方式
- PAT甲级练习1008. Elevator (20)
- hdu4496
- 腾讯任职职级
- 从Git版本控制中删除文件
- 在腾讯开发QQ IM 的工作体验
- ShopWWI S3版本修复计划任务功能
- String,StringBuffer,StringBuilder个人认为较重要的区别
- 论游戏中Buff的实现
- 腾讯QQ是用什么语言开发的