문자열 압축(python)

Effy_ee·2023년 9월 22일
0

코딩테스트

목록 보기
56/118

💻 답안

s=input()
def solution(s):
	count=0
	alphabet=['A','B','C','D','E','F','G','H','I','J','K','L','M',
	'N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
	answer=''
	if s[0]=='1':
		answer+='1'
	for i in range(0,len(s)-1):
		if s[i]==s[i+1]:
			count+=1
		else:
			answer+=alphabet[count]
			count=0
	answer+=alphabet[count]	
	print(answer)

solution(s)
			

0개의 댓글