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 }
  • 相关阅读:
    JQuery对象与Dom对象相互转化
    JQuery练习demo2
    ExtJs简单的登录界面制作
    JQuery练习demo1(隔行变色)
    html标签label的for属性
    Android环境搭建(Windows)
    JQuery表格操作练习
    ExtJs简单动态ComboBox
    Asp.Net母版页的使用
    SQL经典语句大全
  • 原文地址:https://www.cnblogs.com/PureJava/p/10497964.html
Copyright © 2011-2022 走看看