프로그래머스 131128 숫자 짝꿍

Jmnote (토론 | 기여)님의 2023년 12월 12일 (화) 01:00 판 (새 문서: ==개요== {{프로그래머스|레벨=1|페이지=2|분류=연습문제}} ==C++== <syntaxhighlight lang='cpp'> #include <string> #include <vector> #include <map> using namespace std...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

프로그래머스 131128 숫자 짝꿍

2 C++[ | ]

#include <string>
#include <vector>
#include <map>
using namespace std;

string solution(string X, string Y) {
    map<char,int> m1;
    map<char,int> m2;
    for(char c: X) m1[c]++;
    for(char c: Y) m2[c]++;
    string answer = "";
    for(char c='9'; c>='0'; c--) {
        if(m1.find(c) == m1.end()) continue;
        if(m2.find(c) == m2.end()) continue;
        for(int i=0; i<min(m1[c], m2[c]); i++) answer += c;
    }
    if(answer == "") return "-1";
    if(answer[0] == '0') return "0";
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}