您的位置:首页 > 其它

杭电OJ 1008

2018-03-06 16:32 281 查看


很简单的一道题,代码如下://杭电oj 1008 张艺川 2018/3/6
#include<iostream>
using namespace std;
int main(){
int N;//N次楼层请求
int upStairs = 6;//上楼需要6s
int downStairs = -4;//下楼需要4s
int stay = 5;//每一次停留需要5秒

while (cin >> N && N != 0){
int current = 0;//当前楼层
int next = 0;//下一个请求的楼层
int total = 0;//总时间
int difference = 0;//楼层的差值

for (int i = 0; i < N; i++){
cin >> next;
difference = next - current;
if (difference>0){
total += difference*upStairs;
}
else{
total += difference*downStairs;
}
total += stay;
current = next;
}
cout << total<< endl ;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: