IT/coding study

[programmers] COS Pro 1급 Python 모의고사 메모장(python)

seyeonHello 2024. 4. 21. 01:02

사내 자격증 취득 지원비를 받기 위해 cos 문제를 풀어보았습니다. 

def solution(K, words):
    # 여기에 코드를 작성해주세요.
    answer = 1
    cnt=0
    for i in range(len(words)):
        if cnt+len(words[i])<=K:
            cnt+=len(words[i])+1
        else:
            cnt=len(words[i])+1
            answer+=1
    return answer