Skip to content

Commit 333a790

Browse files
committed
[BOJ] 4358 생태학 (S2)
1 parent 3504732 commit 333a790

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

심수연/5주차/260128.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# https://www.acmicpc.net/problem/4358
2+
3+
import sys
4+
input = sys.stdin
5+
6+
dict = {}
7+
8+
for i in input:
9+
word = i.strip()
10+
if word in dict:
11+
dict[word] += 1
12+
else:
13+
dict[word] = 1
14+
15+
# print(dict)
16+
# {'Red Alder': 1, 'Ash': 4, 'Aspen': 1, 'Basswood': 1, 'Beech': 1, 'Yellow Birch': 1, 'Cherry': 1, 'Cottonwood': 1, 'Cypress': 1, 'Red Elm': 1, 'Gum': 1, 'Hackberry': 1, 'White Oak': 3, 'Hickory': 1, 'Pecan': 1, 'Hard Maple': 1, 'Soft Maple': 1, 'Red Oak': 2, 'Poplan': 1, 'Sassafras': 1, 'Sycamore': 1, 'Black Walnut': 1, 'Willow': 1}
17+
18+
# 조건: 사전순으로 출력하고, 그 종이 차지하는 비율을 백분율로 소수점 4째자리까지 반올림
19+
20+
# 사전순으로 출력
21+
# lambda word
22+
# 소문자로 바꿨을 때 min부터 나와야 함
23+
sorted_dict = sorted(dict, key=lambda word: word.lower())
24+
# ['Ash', 'Aspen', 'Basswood', 'Beech', 'Black Walnut', 'Cherry', 'Cottonwood', 'Cypress', 'Gum', 'Hackberry', 'Hard Maple', 'Hickory', 'Pecan', 'Poplan', 'Red Alder', 'Red Elm', 'Red Oak', 'Sassafras', 'Soft Maple', 'Sycamore', 'White Oak', 'Willow', 'Yellow Birch']
25+
26+
total = sum(dict.values())
27+
28+
for word in sorted_dict:
29+
ratio = dict[word] / total * 100
30+
print(f"{word} {ratio:.4f}") # 소수점 4째자리까지 반올림
31+

0 commit comments

Comments
 (0)