C++ 맵 값으로 정렬

Jmnote (토론 | 기여)님의 2023년 9월 10일 (일) 14:33 판 (→‎정수형 값 정렬)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

C++ 맵 값으로 정렬

2 정수형 값 정렬[ | ]

#include <iostream>
#include <map>
using namespace std;

int main() {
    map<string, int> m = {{"apple",11}, {"banana",1}, {"cherry",2}};

    map<int, string> mm;
    for(auto& it: m) mm.insert({it.second, it.first});
    for(auto& it: mm) {
        cout << it.first << ':' << it.second << endl;
    }
}

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}