http://acm.hdu.edu.cn/showproblem.php?pid=1008
#include<iostream>
using namespace std;
int num;
void elavator(int *b)
{
int time=0;
for(int i=1;i<=num;i++){
if(b[i]>b[i-1])
time+=(b[i]-b[i-1])*6;
else if(b[i]<b[i-1])
time+=(b[i-1]-b[i])*4;
}
cout<<time+5*num<<endl;
}
int main()
{
int a[102];
a[0]=0;
while(cin>>num&&num){ //***
for(int i=1;i<=num;i++)
cin>>a[i];
elavator(a);
}
return 0;
}
http://acm.hdu.edu.cn/showproblem.php?pid=1008
#include<iostream>
using namespace std;
int num;
void elavator(int *b)
{
int time=0;
for(int i=1;i<=num;i++){
if(b[i]>b[i-1])
time+=(b[i]-b[i-1])*6;
else if(b[i]<b[i-1])
time+=(b[i-1]-b[i])*4;
}
cout<<time+5*num<<endl;
}
int main()
{
int a[102];
a[0]=0;
while(cin>>num&&num){ //***
for(int i=1;i<=num;i++)
cin>>a[i];
elavator(a);
}
return 0;
}
#include<iostream>
using namespace std;
int num;
void elavator(int *b)
{
int time=0;
for(int i=1;i<=num;i++){
if(b[i]>b[i-1])
time+=(b[i]-b[i-1])*6;
else if(b[i]<b[i-1])
time+=(b[i-1]-b[i])*4;
}
cout<<time+5*num<<endl;
}
int main()
{
int a[102];
a[0]=0;
while(cin>>num&&num){ //***
for(int i=1;i<=num;i++)
cin>>a[i];
elavator(a);
}
return 0;
}