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 }
  • 相关阅读:
    Vue实例
    Vue介绍
    Vue相关知识点记录
    JS面向对象设计-创建对象
    JS面向对象设计-理解对象
    软件工程基础 完结撒花
    深度学习 基于CNN的纹理合成实践【附python实现】
    图像处理 傅里叶正逆变换与余弦正逆变换 【附C++实现】
    Webviz
    Webviz
  • 原文地址:https://www.cnblogs.com/PureJava/p/10497964.html
Copyright © 2011-2022 走看看