본문 바로가기
Coding Test/Programmers

[Programmers] (정렬) Lv 2. 가장 큰 수

by song.ift 2023. 7. 24.

https://school.programmers.co.kr/learn/courses/30/lessons/42746

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

string solution(vector<int> numbers) {
    ::sort(numbers.begin(), numbers.end(), [](auto a, auto b) {
        string strA = to_string(a);
        string strB = to_string(b);

        return (strA == strB || strA + strB < strB + strA) ? false : true;
    });

    string zero;
    string answer = ::accumulate(numbers.begin(), numbers.end(), string(""), [&](auto str, auto i) {
        if (i > 0) return str + to_string(i);
        else zero += "0";
        return str;
    });
    return answer.empty() ? "0" : answer + zero;
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/tree/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/lv2/42746.%E2%80%85%EA%B0%80%EC%9E%A5%E2%80%85%ED%81%B0%E2%80%85%EC%88%98

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글