• [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 }
  • 相关阅读:
    DateUtils
    Java静态绑定与动态绑定
    Mysql中实现递归查询
    架构一、核心概念
    Spring cron 表达式
    MySql点点滴滴(一)之可视化工具介绍
    java中注解的使用与实例
    3、第一个Python程序
    CSS命名
    如何在Notepad++ 中成功地安装Emmet 插件
  • 原文地址:https://www.cnblogs.com/PureJava/p/10497964.html
Copyright © 2020-2023  润新知