[백준] 10610 : 30 - Python

Chooooo·2022년 10월 31일
0

알고리즘/백준

목록 보기
23/182


그리디 알고리즘

문제해결
30의 배수를 찾기 전 3의 배수부터 생각.
그리고 그 뒤에 0 하나 더 붙이면 그게 30의 배수니까 3의 배수를 먼저 생각했으면 됐음

소스코드

import sys


data = list(map(int, input()))
data.sort(reverse = True)
res = 0
for i in range(len(data)):
    res = res * 10 + data[i]

if res % 10 != 0 or res % 3 != 0:
    print(-1)
else:
    print(res)
profile
back-end, 지속 성장 가능한 개발자를 향하여

0개의 댓글