공부/알고리즘
프로그래머스 가장 큰 수 c++ solution
토고미
2021. 9. 5. 23:20
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool myfunc(string a, string b){
return a+b > b+a ? true : false;
}
string solution(vector<int> numbers) {
string answer = "";
vector<string> v;
for(auto n : numbers)
v.push_back(to_string(n));
sort(v.begin(), v.end(), myfunc);
if(v.at(0) == "0")
return "0";
for(auto b : v){
answer += b;
}
return answer;
}
가장 큰 수 C++ (정렬)[프로그래머스]
※ 저의 풀이가 무조건적인 정답은 아닙니다. 다른 코드가 좀더 효율적이고 좋을 수 있습니다. 다른사람들의 풀이는 언제나 참고만 하시기 바랍니다. 문제 주소입니다. https://programmers.co.kr/learn/c
mungto.tistory.com
이분꺼 참고함