"C++ 맵 값으로 정렬"의 두 판 사이의 차이

(새 문서: ==개요== ;C++ 맵 값으로 정렬 ==정수형 값 정렬== <syntaxhighlight lang='cpp' run> #include <iostream> #include <map> using namespace std; int main() { map<string, i...)
 
 
9번째 줄: 9번째 줄:


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


     map<int, string> mm;
     map<int, string> mm;

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 }}