https://programmers.co.kr/learn/courses/30/lessons/42746
코딩테스트 연습 - 가장 큰 수
0 또는 양의 정수가 주어졌을 때, 정수를 이어 붙여 만들 수 있는 가장 큰 수를 알아내 주세요. 예를 들어, 주어진 정수가 [6, 10, 2]라면 [6102, 6210, 1062, 1026, 2610, 2106]를 만들 수 있고, 이중 가장 큰 ��
programmers.co.kr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <string> #include <vector> #include <algorithm> #include <iostream> using namespace std; bool cmp(const string& a, const string& b) { return a + b > b + a; } string solution(vector<int> numbers) { string answer = ""; vector<string> ns; for (int n : numbers) ns.push_back(to_string(n)); sort(ns.begin(), ns.end(), cmp); for (auto s : ns) answer += s; if (answer[0] == '0') answer = "0"; return answer; } | cs |
'Problem-Solving > Programmers' 카테고리의 다른 글
[프로그래머스][level2] 행렬 테두리 회전하기 (C++) (0) | 2021.08.06 |
---|---|
[프로그래머스][level2] 거리두기 확인하기 (C++) (0) | 2021.08.06 |
[프로그래머스] Level2 - 큰 수 만들기(C++) (0) | 2020.07.14 |
[프로그래머스] Level2 - 조이스틱 (C++) (0) | 2020.07.14 |
[프로그래머스] Level2 - 더 맵게 (C++) (0) | 2020.07.07 |