Skip to content
On this page

04_Loop_11.py

WARNING

โค้ดกาวมากครับ อย่าลอกเลย 😭😭😭

ทำเองเถอะนะครับ จะได้ทำข้อสอบได้ 🥲🥲🥲

py
# pylint: disable=global-statement

# O(N²) brrrrrrr

encoded = ""


def cum(curr: str, count: int, rem: str) -> None:
    global encoded

    if not len(rem):
        encoded += curr + ' ' + str(count) + ' '
        return

    if curr == rem[0]:
        cum(curr, count + 1, rem[1:])
    else:
        encoded += curr + ' ' + str(count) + ' '
        cum(rem[0], 1, rem[1:])


s = input()
cum(s[0], 1, s[1:])

print(encoded)

People who plagiarize Com Prog HW:

People who do Com Prog HW by themself:

Released under the MIT License