HD1008简单题

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
	//ifstream cin("input.txt");
	int floor[100],visit[100];
	memset(visit,0,sizeof(visit));
	int stop=5,upSpeed=6,downSpeed=4,n=0,pre,time;
	while (cin>>n&&n)
	{
		time=0;
		for(int i=0;i<n;i++)
			cin>>floor[i];
		for (int i=0;i<n;i++)
		{
			if(i==0)
				pre=0;
			else
				pre=floor[i-1];
			if(floor[i]>=pre)
				time+=(floor[i]-pre)*upSpeed;
			else
				time+=(pre-floor[i])*downSpeed;
		}
		time+=n*stop;
		cout<<time<<endl;
		n=0;
	}

	return 0;
}


你可能感兴趣的:(HD1008简单题)