https://www.acmicpc.net/problem/4358
4358번: 생태학
프로그램은 여러 줄로 이루어져 있으며, 한 줄에 하나의 나무 종 이름이 주어진다. 어떤 종 이름도 30글자를 넘지 않으며, 입력에는 최대 10,000개의 종이 주어지고 최대 1,000,000그루의 나무가 주어
www.acmicpc.net
소수점 출력
# 소수점 2자리까지 출력 = 3자리에서 반올림
n=52.12546
print('%.2f' %n)
>>> 52.13
import sys
input=sys.stdin.readline
trees={}
total=0
while True:
tree=input().rstrip()
if not tree: # 입력이 비면
break
if tree in trees:
trees[tree]+=1
else:
trees[tree]=1
total+=1
answer=sorted(trees.items(), key=lambda x: x[0])
for i in answer:
print('%s %.4f' %(i[0], (trees[i[0]]/total)*100))
'알고리즘' 카테고리의 다른 글
[백준 알고리즘] 12865번 평범한 배낭. 파이썬(python)/냅색 knapsack (0) | 2022.10.21 |
---|---|
[백준 알고리즘] 9251번 LCS 최장 공통 부분 수열. 파이썬(python) (1) | 2022.10.21 |
[백준 알고리즘] 11652번 카드. 파이썬(python)/ 해시맵, 람다정렬 (0) | 2022.10.19 |
[백준 알고리즘] 2839번 설탕 배달. 파이썬(python) (0) | 2022.10.19 |
[백준 알고리즘] 14881번 물통 문제. 파이썬(python)/ 최대공약수 (0) | 2022.10.19 |