본문 바로가기
프로그래머스

이중우선순위큐 C++

by paysmile 2019. 9. 29.
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<string> operations) {
	vector<int> answer;
	vector<int> v;

	for (int i = 0; i < operations.size(); i++) {
		if (operations[i][0] == 'D') {
			sort(v.begin(), v.end());
			if (v.size() == 0)
				continue;
			else {
				if (operations[i][2] == '1')
					v.erase(v.begin() + v.size() - 1);
				else
					v.erase(v.begin());
			}
		}
		else {
			v.push_back(stoi(operations[i].substr(2)));
		}
	}
	if (v.size() == 0) {
		answer.push_back(0);
		answer.push_back(0);
	}
	else {
		sort(v.begin(), v.end());
		answer.push_back(v[v.size() - 1]);
		answer.push_back(v[0]);
	}
	return answer;
}

'프로그래머스' 카테고리의 다른 글

순위 C++  (0) 2019.09.30
저울 C++  (0) 2019.09.30
여행경로 C++  (0) 2019.09.29
입국심사 C++  (0) 2019.09.28
디스크 컨트롤러  (0) 2019.09.28