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 }
  • 相关阅读:
    SQL Server 2005 全文搜索包括改进和更新的干扰词文件FROM MS KB
    服务器内存选项From MS
    跳过事务复制中的错误
    WP7基础补充
    TaoBaoAPI简介3
    登录功能代码
    TaoBaoApI简介1
    TaoBaoAPI简介2
    WP7基础学习第十三讲
    WP7基础学习第十四讲
  • 原文地址:https://www.cnblogs.com/PureJava/p/10497964.html
Copyright © 2011-2022 走看看