반응형

백준 문제 링크

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

 

4358번: 생태학

프로그램은 여러 줄로 이루어져 있으며, 한 줄에 하나의 나무 종 이름이 주어진다. 어떤 종 이름도 30글자를 넘지 않으며, 입력에는 최대 10,000개의 종이 주어지고 최대 1,000,000그루의 나무가 주어

www.acmicpc.net

 

트라이 Trie 자료구조

파이썬을 이용하면 너무나 쉽게 풀 수 있다. 특히, startwith, endwith, in, not in ... 등

다만, 시간초과 문제는 항상 뒤따르기 때문에 내장함수가 아닌 방법도 알아놔야 한다는 점...!!

 

 

내 풀이

# boj4358 생태학
# 실버2

import sys
arr = dict()
count = 0
while True:
    word = sys.stdin.readline().rstrip()
    if not word:
        break
    count += 1
    if word in arr:
        arr[word] += 1
    else:
        arr[word] = 1


for k in sorted(arr.keys()):
    print('{0} {1:0.4f}'.format(k, arr[k]/count * 100))

https://github.com/yj0903/python_CodingTest/blob/main/DataStructure/trie/boj4358.py

 

GitHub - yj0903/python_CodingTest: python_problemSolving

python_problemSolving. Contribute to yj0903/python_CodingTest development by creating an account on GitHub.

github.com

 

반응형

+ Recent posts