문제 링크입니다: https://programmers.co.kr/learn/courses/11133/lessons/71167
COS Pro 1급 Python 모의고사 - 메모장
한 줄에 K자를 적을 수 있는 메모장에 영어 단어들을 적으려 합니다. 영어 단어는 정해진 순서로 적어야 하며, 단어와 단어 사이는 공백 하나로 구분합니다. 단, 한 줄의 끝에 단어 하나를 완전히
programmers.co.kr
회사에서 COS Pro 1급을 따면 상금을 준다고 해서 재미로 풀어봤습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 다음과 같이 import를 사용할 수 있습니다. | |
# import math | |
def solution(K, words): | |
# 여기에 코드를 작성해주세요. | |
answer = 0 | |
temp = "" | |
for word in words: | |
if temp == "": | |
temp = temp + word | |
elif len(temp + word) + 1 > K: | |
temp = word | |
answer = answer + 1 | |
else: | |
temp = temp + "_" + word | |
if temp != "": | |
answer = answer + 1 | |
return answer | |
# 아래는 테스트케이스 출력을 해보기 위한 코드입니다. | |
K = 10 | |
words = ["nice", "happy", "hello", "world", "hi"] | |
ret = solution(10, words) | |
# [실행] 버튼을 누르면 출력 값을 볼 수 있습니다. | |
print("solution 함수의 반환 값은", ret, "입니다.") |

개발환경: Programmers IDE
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'Python > COS Pro 1급 Python 모의고사' 카테고리의 다른 글
[Programmers] 숫자 뽑기 (0) | 2022.05.11 |
---|---|
[Programmers] 꽃피우기 (3) | 2022.05.11 |
[Programmers] 카드셔플 (0) | 2022.05.11 |
[Programmers] 보드게임 (0) | 2022.05.11 |
[Programmers] 종이접기 (0) | 2022.05.11 |