## 문제
숫자를 섞어 30이 되는 가장 큰 수로 만들기
일단 0이 하나 있어야 하고 각자리 합이 3이 되어야 한다.
결과는 0을 따로 빼고, 내림차순 정렬하고 0을 뒤에 붙여주면 된다.
## CODE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
input = lambda : sys.stdin.readline().rstrip() | |
n = input() | |
# 숫자합이 3배수 | |
is3x = 0 | |
for tmp in n: | |
is3x += int(tmp) | |
if is3x%3 != 0: | |
print(-1) | |
else: | |
# 2 숫자에 0있는지 | |
if '0' not in n: | |
print(-1) | |
else: | |
# 0의 인덱스 찾기 | |
i = n.find('0') | |
n = n[:i] + n[i+1:] | |
a = list(map(int,list(n))) | |
b = a[:] | |
b.sort(reverse=True) | |
c = list(map(str,b)) | |
print(''.join(c) + '0') |
n.replace('0','') 으로 0 을 다 빼버리면 틀리게된다
2100의 경우 210이라는 결과가 나온다
0 하나의 인덱스를 찾아서 한개만 제외하면 된다.
0 댓글