매일 C++ day 4
2021-05-22
가장 큰 수
https://programmers.co.kr/learn/courses/30/lessons/42746?language=cpp#
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(int a, int b)
{
string tempA = to_string(a) + to_string(b);
string tempB = to_string(b) + to_string(a);
return stoi(tempA) > stoi(tempB);
}
string solution(vector<int> numbers) {
string answer = "";
sort(numbers.begin(), numbers.end(), cmp);
for(auto n : numbers)
{
answer += to_string(n);
}
if(answer.at(0)=='0') answer = '0';
return answer;
}
test test