C++_코딩테스트/컨테이너2 [백준 1927번/C++] 최소 힙 priority_queue에 그냥 greater를 붙이면 될 줄 알았는데 초기화에 기본 컨테이너(vecter가 될 수도 있고 deque일 수도 있음)를 넣어줘야 한다. 답 #include #include #include #include using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N{}, tmp{}; cin >> N; priority_queue queue; for (int i = 0; i > tmp; if (tmp == 0) { if (queue.empty()) { cout 2024. 2. 5. [백준 20920번/C++] 영단어 암기는 괴로워(단어 정렬 문제) -> unordered_map으로 받아서 정렬까지 다 하려고 했는데, map, set은 키로 정렬이 가능하지 second로는 정렬이 불가능하다. 그래서 vector로 옮긴 뒤에 정렬하였다. 정렬 함수를 만들어서 우선순위대로 하였다. string은 비교시 더 작은 것이 사전순으로 앞 숫자기 때문에 기호의 방향에 주의하자. (아스키 코드로 생각하면 편하다) #include #include #include #include using namespace std; unordered_map dictionary; bool compairVec(const pair& A, const pair& B) { if (A.second != B.second) { return A.second > B.second; } else { if .. 2024. 2. 4. 이전 1 다음