Skip to content
CatBus

Tag: greedy algorithm

All the articles with the tag "greedy algorithm".

BOJ10610SILVER 5
nums = str(sys.stdin.readline().strip())
if '0' not in nums:
    print(-1)
else:
    l = [0] * (int(max(nums)) + 1)
    s = ''
    sum = 0
    for i in nums:
        l[int(i)] += 1
    for i in range(len(l)-1, 0, -1):
        s += str(i) * l[i]
        sum += i * l[i]
    if sum % 3 == 0: print(int(s) * (10 ** l[0]))
    else: print(-1)

30

백준 10610번 '30' (실버 5) 문제 풀이. math, string, greedy algorithm 로 접근했다.

2022.02.04·3분·math