-
Notifications
You must be signed in to change notification settings - Fork 1
/
가장 큰 수.cpp
50 lines (38 loc) · 945 Bytes
/
가장 큰 수.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 가장 큰 수 (정렬)
// https://programmers.co.kr/learn/courses/30/lessons/42746?language=cpp
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<class T>
void Print(const vector<T>& v, string tag = "----------------------------")
{
cout << tag << endl;
for (auto e : v)
{
cout << e << " ";
}
cout << endl;
}
string solution(vector<int> numbers)
{
vector<string> numstr(numbers.size());
for (int i = 0; i < numbers.size(); ++i)
{
numstr[i] = to_string(numbers[i]);
}
sort(begin(numstr), end(numstr), [](const string& a, const string& b)
{
return a + b > b + a;
});
//Print(numstr);
// check case arr = {0, 0}
if (numstr[0] == "0") return "0";
string answer = "";
for (int i = 0; i < numstr.size(); ++i)
{
answer += numstr[i];
}
return answer;
}