๋ฐฑ์ค€

๋ฐฑ์ค€ 1919 ์• ๋„ˆ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ - ํŒŒ์ด์ฌ

stoneeee 2022. 3. 26. 19:36

https://www.acmicpc.net/problem/1919

 

1919๋ฒˆ: ์• ๋„ˆ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

๋‘ ์˜์–ด ๋‹จ์–ด๊ฐ€ ์ฒ ์ž์˜ ์ˆœ์„œ๋ฅผ ๋’ค๋ฐ”๊พธ์–ด ๊ฐ™์•„์งˆ ์ˆ˜ ์žˆ์„ ๋•Œ, ๊ทธ๋Ÿฌํ•œ ๋‘ ๋‹จ์–ด๋ฅผ ์„œ๋กœ ์• ๋„ˆ๊ทธ๋žจ ๊ด€๊ณ„์— ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด occurs ๋ผ๋Š” ์˜์–ด ๋‹จ์–ด์™€ succor ๋Š” ์„œ๋กœ ์• ๋„ˆ๊ทธ๋žจ ๊ด€๊ณ„์— ์žˆ๋Š”๋ฐ, occurs

www.acmicpc.net

 

๊ฐ๊ฐ์˜ ๋‹จ์–ด ํฌํ•จ๋œ ์•ŒํŒŒ๋ฒณ์˜ ์ข…๋ฅ˜์™€ ๊ฐœ์ˆ˜๋ฅผ ์นด์šดํŒ…ํ•œ ๋’ค, ๊ทธ ์ฐจ์ด๋ฅผ ์ด์šฉํ•˜๋ฉด ๋‹ต์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 

#1: key๊ฐ’์ด ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž์ด๊ณ , value๊ฐ’์ด 0์ธ dictionary๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค.

#2: ์ฒซ๋ฒˆ์งธ ๋‹จ์–ด๋ฅผ input ๋ฐ›๊ณ , ๊ทธ ๋‹จ์–ด์—์„œ ์•ŒํŒŒ๋ฒณ์ด ํ•˜๋‚˜ ๋‚˜์˜ฌ ๋•Œ๋งˆ๋‹ค ํ•ด๋‹น ์•ŒํŒŒ๋ฒณ์— ๋Œ€ํ•œ dictionary value๊ฐ’์ด 1์”ฉ ์ฆ๊ฐ€ํ•˜๋„๋ก ํ–ˆ๋‹ค.

#3: ๋‘๋ฒˆ์งธ ๋‹จ์–ด๋ฅผ input ๋ฐ›๊ณ , ๊ทธ ๋‹จ์–ด์—์„œ ์•ŒํŒŒ๋ฒณ์ด ํ•˜๋‚˜ ๋‚˜์˜ฌ ๋•Œ๋งˆ๋‹ค ํ•ด๋‹น ์•ŒํŒŒ๋ฒณ์— ๋Œ€ํ•œ dictionary value๊ฐ’์ด 1์”ฉ ๊ฐ์†Œํ•˜๋„๋ก ํ–ˆ๋‹ค.

#4: Dictionary value์˜ ์ ˆ๋Œ“๊ฐ’์„ ๋ชจ๋‘ ๋”ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค.

 

 >>> ๋งŒ์•ฝ ๋‘ ๋‹จ์–ด์— 'a'์˜ ๊ฐœ์ˆ˜๊ฐ€ 3๊ฐœ์”ฉ ํฌํ•จ๋˜์–ด ์žˆ๋‹ค๋ฉด ์• ๋„ˆ๊ทธ๋žจ์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ 'a'๋ฅผ ์ œ๊ฑฐํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค. ์ด ๋•Œ, dictionary์˜ value๊ฐ’์€ 0์ด๋‹ค. ๋‘ ๋‹จ์–ด์—์„œ 'b'์˜ ๊ฐœ์ˆ˜๊ฐ€ ํ•˜๋‚˜ ์ฐจ์ด ๋‚œ๋‹ค๋ฉด dictionary์˜ value๊ฐ’์€ 1 ๋˜๋Š” -1์ผ ๊ฒƒ์ด๋‹ค. ๋‘ ๋‹จ์–ด์—์„œ ์ œ๊ฑฐํ•ด์•ผ ํ•  'b'์˜ ๊ฐœ์ˆ˜๋Š” dictionary value์˜ ์ ˆ๋Œ“๊ฐ’์ธ 1๊ฐœ์ด๋‹ค. ์ด๋Ÿฐ ์‹์œผ๋กœ dictionary value๋“ค์˜ ์ ˆ๋Œ“๊ฐ’๋“ค์„ ๋”ํ•˜๋ฉด ์ œ๊ฑฐํ•ด์•ผ ํ•  ๋ฌธ์ž์˜ ์ˆ˜๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 

#1
alphabet = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for abc in alphabet:
    dic[abc] = 0

#2
word1 = input()
for letter in word1:
    dic[letter] += 1

#3
word2 = input()
for letter in word2:
    dic[letter] -= 1

#4
ans = 0
for i in dic:
    ans += abs(dic[i])

print(ans)