简单题,一次通过。
思路:没什么可说的,纯计算。
代码:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int N;
int i;
int iTotal;
int iDiff;
while(scanf("%d",&N)!=EOF)
{
if(N==0)break;
iTotal = 0;/*初始化停留时间*/
iDiff = 0;
int *p = (int*)malloc(sizeof(int)*N);
for(i=0;i<N;i++)
{
scanf("%d",&p[i]);
}
iTotal = N * 5;/*每层停留的时间*/
for(i=0;i<N;i++)
{
if(i==0)
{
iDiff = p[i] - 0;
}
else
{
iDiff = p[i] - p[i-1];
}
if(iDiff<0)
{
/*说明这种情况下,电梯是向下运行的*/
iTotal += abs(iDiff)*4;
}
if(iDiff>0)
{
/*电梯向上运行 */
iTotal += iDiff*6;
}
}
/*for(i=0;i<N;i++)
printf("%d\n",p[i]);*/
printf("%d\n",iTotal);
free(p);
}
system("PAUSE");
return 0;
}