zoukankan      html  css  js  c++  java
  • [PAT] 1008 Elevator (20 分)Java

    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


     1 import java.util.Scanner;
     2 
     3 /**
     4  * @Auther: Xingzheng Wang
     5  * @Date: 2019/2/18 20:57
     6  * @Description: pattest
     7  * @Version: 1.0
     8  */
     9 public class PAT1008 {
    10     public static void main(String[] args) {
    11         Scanner sc = new Scanner(System.in);
    12         int n = sc.nextInt();
    13         int a, b = 0, c = 5 * n;
    14         for (int i = 0; i < n; i++) {
    15             a = b;
    16             b = sc.nextInt();
    17             if (b < a) {
    18                 c += 4 * (a - b);
    19             } else {
    20                 c += 6 * (b - a);
    21             }
    22         }
    23         System.out.print(c);
    24     }
    25 }
  • 相关阅读:
    MySQL 字符串与时间操作函数
    Redis消息订阅,事务,modules
    Redis数据结构
    Redis数据类型String
    Redis
    网络协议原理和lvs三种模型,调度算法和keepalived
    TCP连接状态,SYNC_RECV,CLOSE_WAIT,TIME_WAIT
    arp_ignore和arp_announce
    JMH和Disrupter
    容器CopyOnWriteList,ConcurrentHashMap,ConcurrentSkipListMap,BlockingQueue
  • 原文地址:https://www.cnblogs.com/PureJava/p/10497964.html
Copyright © 2011-2022 走看看