티스토리 뷰
https://programmers.co.kr/learn/courses/30/lessons/42746
코딩테스트 연습 - 가장 큰 수
0 또는 양의 정수가 주어졌을 때, 정수를 이어 붙여 만들 수 있는 가장 큰 수를 알아내 주세요. 예를 들어, 주어진 정수가 [6, 10, 2]라면 [6102, 6210, 1062, 1026, 2610, 2106]를 만들 수 있고, 이중 가장 큰
programmers.co.kr
[프로그래머스][C++] 가장 큰 수
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool compare(string a, string b) {
return a + b > b + a;
}
string solution(vector<int> numbers) {
string answer = "";
vector<string> vec;
for (int i : numbers) {
vec.push_back(to_string(i));
}
sort(vec.begin(), vec.end(), compare);
for (string s : vec) {
answer += s;
}
if (answer[0] == '0') return "0";
return answer;
}
'Problem Solving' 카테고리의 다른 글
[Python] List / Tuple / Dictionary / Set 차이점 및 예시 (0) | 2022.09.10 |
---|---|
[Python] Range / Slice 예시 (0) | 2022.09.10 |
[프로그래머스][C++] N-Queen (0) | 2022.06.27 |
[프로그래머스][C++] 행렬의 곱셈 (0) | 2022.06.27 |
[프로그래머스][C++] 하노이의 탑 (0) | 2022.06.26 |
댓글