본문 바로가기

알고리즘/프로그래머스 문제풀이

[프로그래머스] 정렬 / 가장 큰 수

#include <string>
#include <vector>
#include<algorithm>
#include<iostream>

using namespace std;

bool cmp(string &a, string &b) {
    return a + b > b + a;
}

string solution(vector<int> numbers) {
    string answer = "";
    vector<string> temp;
    
    for(auto elem : numbers)
        temp.push_back(to_string(elem));
    
    sort(temp.begin(), temp.end(), cmp);
    
    for(auto elem : temp)
        answer += elem;
    
    if(answer[0] == '0')
        return "0";
    
    return answer;
}