๐Ÿ—๏ธ Algorithm/โฌ› ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

โฌ› [Programmers] [Python] [Level1] ์ถ”์–ต ์ ์ˆ˜

Dbswnstjd 2023. 4. 13. 12:03

๋ฌธ์ œ

https://school.programmers.co.kr/learn/courses/30/lessons/176963

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

ํ’€์ด

# ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ - ์ถ”์–ต ์ ์ˆ˜
def solution(name, yearning, photo):
    answer = []
    d = {}
    for i in range(len(name)):
          d[name[i]] = yearning[i]
    for i in range(len(photo)):
        res =0 
        for j in range(len(photo[i])):
            if photo[i][j] in d:
                res += d[photo[i][j]]
        answer.append(res)
    return answer


print(solution(["may", "kein", "kain", "radi"], [5, 10, 1, 3], [["may", "kein", "kain", "radi"],["may", "kein", "brin", "deny"], ["kon", "kain", "may", "coni"]]))
print(solution(["kali", "mari", "don"],[11, 1, 55],[["kali", "mari", "don"], ["pony", "tom", "teddy"], ["con", "mona", "don"]]))
print(solution(["may", "kein", "kain", "radi"],[5, 10, 1, 3],[["may"],["kein", "deny", "may"], ["kon", "coni"]]))

๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์ด์šฉํ•ด ๊ฐ’์ด ์žˆ์œผ๋ฉด ๋”ํ•ด์ฃผ๊ณ  ์—†๋‹ค๋ฉด ๋„˜์–ด๊ฐ„๋‹ค.