Skip to content

Conversation

@kchung1995
Copy link
Contributor

📘 풀이한 문제
  • 가장 큰 수 (프로그래머스)

⭐ 문제에서 주로 사용한 알고리즘
  • 비교, 정렬

📜 대략적인 코드 설명
  • 입력받은 숫자를 비교하기 위해, 모든 숫자를 4자리로 만들어 줍니다.
  • 맨 앞자리가 같은 숫자일 경우, 길이가 짧은 숫자가 weight가 높습니다. 예를 들어, 3과 30을 330, 303으로 만드느냐의 차이입니다.
  • 이를 위해, 숫자를 반복하여 4자리로 만듭니다. 3은 3333, 30은 3030으로 만듭니다.
    *숫자가 0일 경우, 위 과정을 생략하고 0으로 진행합니다.
  • 만들어진 4자리 숫자와 원래 값을 pair로 vector에 push해 줍니다.
  • 만들어진 4자리 숫자를 기준으로 정렬합니다.
  • vector의 뒤에서부터 원래 값을 꺼내어 answer의 뒤에 더하고, vector는 pop_back해 줍니다.
  • 만약 모든 숫자의 값이 0일 경우, 답이 string이므로 00000의 형태로 나올 수 있습니다. 이를 방지하기 위해, string = "0"이라면, 더 이상 0을 추가하지 않도록 조건을 추가해 줍니다.

@ChanhuiSeok ChanhuiSeok added the problem-solved Indication that this problem is solved label Nov 15, 2020
@ChanhuiSeok ChanhuiSeok merged commit d61ae95 into CodeTest-StudyGroup:master Nov 15, 2020
@kchung1995 kchung1995 deleted the programmers branch November 15, 2020 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

problem-solved Indication that this problem is solved

2 participants