PTA甲级1008 电梯问题
题目
大意:上楼6秒,下楼4秒,每层停5秒,问总时间。
思路:一个简单的模拟问题。题目给出的第一个数是指共有n个数,即循环n次。
代码:
#include <cstdio>
using namespace std;
int main() {
int n,now=0,total=0,c;
scanf("%d", &n);
while (n-- > 0) {
scanf("%d", &c);
if(c>now){
total += (c-now)*6+5;
}
if(c<now){
total += (now-c)*4+5;
}
now = c;
}
printf("%d", total);
return 0;
}