Skip to main content

BOJ 1919

애너그램 만들기

tip

Clicking the heading will take you to the BOJ problem.

Solution

아이디어는 다 괜찮았는데 절댓값을 생각을 못했었다.

a = input()
b = input()

count_a = [0] * 26
count_b = [0] * 26

for c in a:
    count_a[ord(c) - ord('a')] += 1
for c in b:
    count_b[ord(c) - ord('a')] += 1

answer = 0

for i in range(26):
    if count_a[i] >= count_b[i]:
        answer += count_a[i] - count_b[i]
    else:
        answer += count_b[i] - count_a[i]
       
print(answer)