강의

멘토링

커뮤니티

Inflearn Community Q&A

zenith33's profile image
zenith33

asked

Jeju Coding Base Camp Code Festival: Python 100 Questions

40번 관련 질문드립니다.

Written on

·

154

0

해당 문제를 풀다보니 궁금증이 생겨 질문드립니다.

해당 문제의 경우 주어진 input값만을 생각하면 답을 도출할수 있지만 i가 0부터시작하기때문에 만약 

limit가 50이고 n이 5명이고 각 무게가 5kg라고 가정한다면

모두 탈수있음에도 불구하고 count =  4를 출력되어 

이부분에 대한 접근을 고민하게 되었습니다. 

제 경우는 아래와 같이 작성해보았는데 혹시 문제되는 부분이 있을지 검토해주셨으면 합니다 ^^

total = 0
count = 0
limit = int(input()) # 무게제한
n = int(input()) #몇명이 탑승

for i in range(1, n+1):
    weight = int(input())
    if total <= limit:
        total += weight
        print(f"i값은 {i}")
        count = i
        if total >= limit:
            count = i-1
print(f"{count} 명 탑승가능합니다")
python코테 준비 같이 해요!

Answer

This question is waiting for answers
Be the first to answer!
zenith33's profile image
zenith33

asked

Ask a question