백준 14659 c++

magicdrill·2024년 6월 29일

백준 문제풀이

목록 보기
380/673

백준 14659 c++

간단한 문제인데, 봉우리들이 순환한다고 착각해서 구현하느라 시간을 낭비했다. 봉우리는 순환하지 않는 구조이다.

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

void input_height(vector <int>& height)
{
	int N;
	int i, temp;

	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> temp;
		height.push_back(temp);
	}

	return;
}

void find_answer(vector<int>& height)
{
	int i, j;
	int temp;
	int max = 0;

	for (i = 0; i < height.size() - 1; i++)
	{
		temp = 0;
		for (j = i + 1; j < height.size(); j++)
		{
			if (height[j] < height[i])
			{
				temp++;
			}
			else
			{
				break;
			}
		}
		if (temp > max)
		{
			max = temp;
		}
	}
	cout << max << "\n";

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	vector <int> height;

	input_height(height);
	find_answer(height);

	return 0;
}

0개의 댓글