PAT 1008

Elevator

按照給定順序處理,對於每一個數字(可以理解爲每一個人)都要停留5秒鐘。
#include <iostream>
#include <stack>
#include <vector>
#include <string>
using namespace std;

vector<int>v;

int main()
{
	int n, x, i;
	cin>>n;
	for(i = 0; i < n; i ++) 
	{
		cin>>x;
		v.push_back(x);
	}

	int pre = 0;
	int ans = 0;
	for(i = 0; i < n; i ++)
	{
		x = v[i];
		if(x > pre)
		{
			ans += (x - pre) * 6;
		}
		else if(x < pre)
		{
			ans += (pre - x) * 4;
		}
		ans += 5;
		pre = x;
	}
	cout<<ans<<endl;
    return 0;
}


發佈了60 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章