프로그래머스 c++ 가장 큰 수

jaranda·2022년 3월 23일
0

가장 큰 수

결과

문제풀이

#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
using namespace std;
bool cmp(string a, string b) {
    return a + b > b + a;
}
string solution (vector < int >numbers)
{
    vector<string> v;
    string ans ="";
    for(auto i:numbers)
    v.push_back(to_string(i));
    sort(v.begin(),v.end(),cmp);
    if(v[0]=="0")
        return "0";
    stringstream ss;
    for(auto i:v)
        ss << i;
    ans= ss.str();    
  return ans;
}

int로 들어온 벡터를 스트링으로 바꾸고 , 스트링기준 합쳤을때 큰값기준으로 정렬한뒤 합쳐서 반환했다.

profile
자라는 개발자

0개의 댓글

관련 채용 정보