A1008 Elevator (20分)

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

Solution: 

#include <iostream>
using namespace std;
int main() {
    int N;
    cin >> N;
    int nextfloor;
    int tempfloor = 0;
    int time = 0;
    for (int i = 0; i < N; i++) {
        cin >> nextfloor;
        if (nextfloor > tempfloor) {
            time += (nextfloor - tempfloor) * 6 + 5;
            tempfloor = nextfloor;
        } else if (nextfloor < tempfloor){
            time += (tempfloor - nextfloor) * 4 + 5;
            tempfloor = nextfloor;
        } else {
            time += 5;
        }
    }
    cout << time;
    return 0;
}

 

当你在使用Masm进行汇编语言编程,遇到文件操作相关的I/O错误时,首先需要确定错误代码的具体含义。在Masm中,I/O错误代码通常提供了错误的初步类和可能的原因。比如错误代码A1000表示无法打开文件,而A1001则意味着关闭文件时遇到了I/O错误。每种错误代码都对应着特定的错误类型和解决方法。例如,对于A1000错误,你需要检查以下几点: 参考资源链接:[Masm错误代码解析与解决方法](https://wenku.youkuaiyun.com/doc/2fk3supoza?spm=1055.2569.3001.10343) 1. 文件路径是否正确,文件是否存在。 2. 文件是否被其他进程锁定。 3. 文件名是否符合系统要求,没有错误或特殊字符。 4. 尝试写入的文件是否为只读文件。 5. 检查磁盘空间是否充足。 6. 查看当前目录是否有文件数量的限制。 7. 确认设备没有被移除或未准备好。 对于A1001错误,这通常是因为在文件操作过程中设备被意外移除,因此你需要确保在操作文件前设备已经正确连接,并且在文件操作期间保持连接稳定。 更深层次的错误处理可能涉及优化代码结构,比如避免不必要的宏定义,合理安排嵌套层级,确保宏指令的正确配对。例如,A1007错误指出嵌套过深,你可能需要通过重构代码减少嵌套层次。对于A1008错误,检查宏定义确保每个ENDM指令都有对应的宏开始指令。如果遇到A1009错误,即代码行过长,则需要将长代码行拆为更短的逻辑行。 在上述步骤都无法解决问题的情况下,查阅《Masm错误代码解析与解决方法》会是一个明智的选择。该指南提供了关于编程过程中可能出现的问题的详细解析,包括文件操作错误、编译器限制以及指令结构错误等,通过这些信息,你可以更准确地定位问题并采取有效的解决措施。 参考资源链接:[Masm错误代码解析与解决方法](https://wenku.youkuaiyun.com/doc/2fk3supoza?spm=1055.2569.3001.10343)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值