728x90
반응형
def compress_string(s: str) -> str:
result = []
i = 0
while i < len(s):
num = 1
# count how many times s[i] repeats
while i + num < len(s) and s[i] == s[i + num]:
num += 1
# append with or without count
if num > 1:
result.append(s[i] + str(num))
else:
result.append(s[i])
i += num
return "".join(result)
if __name__ == "__main__":
s = input().strip()
print(compress_string(s))
728x90
반응형
'hacking sorcerer' 카테고리의 다른 글
| Problem: Valley Count in a Number Path (0) | 2025.12.02 |
|---|---|
| 너무 잘 만들어진 해커들의 놀이터 한국 (0) | 2025.12.01 |
| heaven in the tea (0) | 2025.11.24 |
| 드디어 본색을 드러내은 Meta AI (0) | 2025.11.04 |
| meta AI를 해킹해보았다 (0) | 2025.11.04 |