Created
May 31, 2017 09:32
-
-
Save nattybear/2be2d35ccba7a655bfed0ff50cbb5e93 to your computer and use it in GitHub Desktop.
점프투파이썬 연습문제 - 글자 압축하기
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
# 사용자 입력 받기 | |
s = input() | |
# 글자를 판단할 변수 생성 | |
a = '' | |
# 글자수를 셀 변수 생성 | |
cnt = 0 | |
for i in s: | |
# 글자를 판단할 변수에 아무 것도 없으면 | |
# 즉 첫번째 글자라면 변수 a에 첫번째 글자를 할당 | |
# 첫번째 글자도 개수를 세야 하므로 cnt 증가 | |
if a == '': | |
a = i | |
cnt += 1 | |
else: | |
# 지금 세려는 글자가 변수 a에 있는 글자라면 | |
# 즉 연속된 글자라면 그냥 개수만 증가 | |
if a == i: | |
cnt += 1 | |
else: | |
# 그렇지 않다면 | |
# 즉 지금 세려는 글자가 앞에 세던 | |
# 글자와 다르다면 | |
# 지금까지 세던 글자를 출력하고 | |
# 다시 새로운 글자를 셈 | |
print(a + str(cnt), end='') | |
a = i | |
cnt = 0 | |
cnt += 1 | |
# 마지막 글자와 개수도 마저 출력 | |
print(a + str(cnt)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
주석의 중요성
결국 너의 알고리즘을 따라함