본문 바로가기
Coding Test/Programmers

[Programmers] (2019 카카오 개발자 겨울 인턴십) Lv 2. 튜플

by song.ift 2023. 6. 16.

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <map>

using namespace std;

bool cmp(const pair<int, int>& a, const 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 tmp;
    for (int i = 1; i < s.length() - 1; i++) {
        if (s[i] != '{' && s[i] != '}' && s[i] != ',') {
            // 숫자일 경우
            tmp += s[i];

            // 10 이상의 수일 경우는 계속 숫자를 넣도록 함.
            if (s[i + 1] != ',' && s[i + 1] != '}') continue;

            // 카운팅
            m[stoi(tmp)]++;
        }
        tmp = "";
    }

    vector<pair<int, int>> vec(m.begin(), m.end());
    
    ::sort(vec.begin(), vec.end(), cmp); // 오름차순 정렬
    ::for_each(vec.begin(), vec.end(), [&](const auto& pp) { answer.push_back(pp.first); });
    
    return answer;
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/blob/f175769e6a1235f6925d396567f15f5427639e32/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/lv2/64065.%E2%80%85%ED%8A%9C%ED%94%8C/%ED%8A%9C%ED%94%8C.cpp

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글