Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔗 문제 링크
생태학
✔️ 소요된 시간
1h
✨ 수도 코드
이전 차시에서 했던 집합과 맵을 이용한 문제를 하나 더 가져왔습니다.
입력에서 나무의 종이 주어지는데, 이 수를 세어서 각 종이 차지하는 비율을 출력하는 문제입니다.
우선 입력 값의 수가 주어지지 않기 때문에 비어있는 입력이 나올 때까지 반복문으로 입력을 받아주었습니다.
파이썬 집합에서는 빈 값인 경우에
+= 1사용이 안 되더라구요그래서 if문으로 처음 입력 받는 종이면
=1, 이미 존재한다면+= 1을 사용하여 입력을 받아주었습니다!>(입력 받을 때마다 count로 전체 수를 세어주었습니다)
모두 카운트 하였다면 각 종의 value 값에 count를 나누고 100을 곱해 백분율 값을 value값에 덮어씌웠습니다.
출력 조건에 맞게 정렬 후 f-string으로 소수 넷째 자리까지 출력하였습니당.
수도코드
📚 새롭게 알게된 내용
f-string(gpt)