问题:
http://acm.hdu.edu.cn/showproblem.php?pid=1008
题解:
水题,重在理解电梯如何运行,答案从Input与Output中找
#include <iostream>
using namespace std;
int main()
{
int n;
while (scanf("%d", &n) && n != 0) {
int total_time = 0;
int next_floor, cur_floor = 0;
while (n-- > 0) {
scanf("%d", &next_floor);
if (next_floor > cur_floor)
total_time += 6 * (next_floor - cur_floor) + 5;
else
total_time += 4 * (cur_floor - next_floor) + 5;
cur_floor = next_floor;
}
printf("%d\n", total_time);
}
return 0;
}