#include <string> #include <vector> #include <queue> #include <algorithm> #include <iostream> using namespace std; vector<int> solution(vector<string> operations) { vector<int> answer; vector<int> q; for(int i = 0; i < operations.size(); i++) { if(operations[i][0] == 'I') { string num = operations[i].substr(2, operations.size()-2); q.push_back(stoi(num)); } else if(operations[i][0] == 'D') { if(q.size() == 0) { continue; } if(operations[i][2] == '1') { // 오름차순 sort(q.begin(), q.end()); q.pop_back(); } else if(operations[i][2] == '-') { // 내림차순 sort(q.begin(), q.end(), greater<int>()); q.pop_back(); } } ; } if(q.size() == 0) { answer.push_back(0); answer.push_back(0); } else { // 오름차순 sort(q.begin(), q.end()); answer.push_back(q[q.size()-1]); answer.push_back(q[0]); } return answer; } | cs |
'Programmers > Level 3' 카테고리의 다른 글
[프로그래머스 3] 여행경로 (C/C++) (★) (0) | 2020.01.09 |
---|---|
[프로그래머스 3] 단어 변환 (C/C++) (0) | 2020.01.09 |
[프로그래머스 3] 네트워크 (C/C++) (0) | 2020.01.09 |
[프로그래머스 3] 베스트 앨범 (C/C++) (★) (0) | 2020.01.07 |
[프로그래머스 3] 하노이의 탑 (C/C++) (0) | 2020.01.04 |