본문 바로가기
알고리즘

[Cos Pro 1급 기출문제/파이썬] 전광판 문구 출력

by Rudy 2023. 1. 15.
def solution(phrases, second):
	answer = ''
	#second=29
	pLen=len(phrases)
	divSecond=second%(pLen*2)
	if divSecond<=pLen:
		answer+='_'*(pLen-divSecond)
		answer+=phrases[:divSecond]
	else:
		answer+=phrases[-(pLen-(divSecond-pLen)):]
		answer+='_'*(divSecond-pLen)
	return answer

각각 문자열이 들어올 때와 나갈 때를 구분하여 if문을 통해 구현하면 된다.

문자열이 들어올 때는 문자열의 길이까지의 시간이고 나갈 때는 문자열 길이 이후까지의 시간이다.

문자열이 들어올 때는 앞을 언더바로 채우고, 뒤를 문자열의 앞에서부터 채운다.

문자열이 나갈 때는 먼저 문자열을 뒤에서부터 채우고 언더바로 채우면 된다.

댓글