HDU1008

#include <iostream>
#include <cmath>
using namespace std;
int caculate_time(int a, int b);

int main()
{
	int n, i, time = 0;
	int array[105];
	while(cin>>n, n != 0)
	{
		for(i=0; i < n; i++)//輸入數組
			cin >> array[i];
		//計算第一個時間
		time = array[0] * 6 + 5;
		for(i=0; i<n-1; i++)//i從0開始時因爲下標爲0和下標爲1也要進行計算
		{
			time = time + caculate_time(array[i], array[i+1]);
		}
		cout << time << endl;
		time = 0;
	}
	return 0;
}

int caculate_time(int a, int b)
{
	int sum = 0;
	if(a - b <0)
	{
		sum = (b - a) * 6 + 5;
	}
	else
	{
		sum = (a - b) * 4 + 5;
	}
	return sum;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章