콘솔창 & 윈도우창/코딩 테스트

프로그래머스 LV.2 튜플

뽀또치즈맛 2026. 1. 7. 12:24

https://school.programmers.co.kr/learn/courses/30/lessons/64065

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

bool cmp (pair<int,int>& a, pair<int,int>& b)
{
    if(a.second == b.second)
        return a.first > b.first;
    return a.second > b.second;
}

vector<int> solution(string s) {
    vector<int> answer;
    
    map<int, int> m;
    string temp = "";
    for(int i =0; i < s.size(); i++)
    {
        if(s[i] != '{' && s[i] != '}' && s[i] != ',')
        {
            temp += s[i];
        }
        
        if(s[i] == '}' || s[i] == ',')
        {
            if(temp == "") continue;
            m[stoi(temp)]++;
            temp = "";
        }
        
    }
    
    vector<pair<int,int>> v(m.begin(), m.end());
    sort(v.begin(), v.end(), cmp);
    
    for(int i = 0; i < v.size(); i++)
    {
        answer.emplace_back(v[i].first);
    }
    
    return answer;
}

'콘솔창 & 윈도우창 > 코딩 테스트' 카테고리의 다른 글

LV.2 미로탈출  (0) 2025.10.26
[백준 골드 1] 1016 제곱 ㄴㄴ 수  (0) 2025.08.11
[백준 실버 1] 1741 소수&팰린드롬  (0) 2025.08.09
회문 순열  (2) 2025.08.07
코딩 인터뷰 문제 6가지  (4) 2025.08.03