ข้อความ THEOS

📋 โจทย์

รับข้อความตัวพิมพ์ใหญ่ยาว 5 ตัว แปลงเป็นรหัส THEOS โดยนับตัวอักษรที่เหมือนกันติดต่อกัน เช่น XYZZZ → 1X1Y3Z

⚠️ ข้อจำกัด

ความยาว = 5 ตัวอักษร (A-Z)

📝 ตัวอย่าง

ตัวอย่างที่ 1
Input:
XYZZZ
Output:
1X1Y3Z
ตัวอย่างที่ 2
Input:
ABCDE
Output:
1A1B1C1D1E
ตัวอย่างที่ 3
Input:
AAAAA
Output:
5A
🔓 ดูเฉลย
s = input()
result = ""
i = 0
while i < len(s):
    c = s[i]
    count = 1
    while i + count < len(s) and s[i + count] == c:
        count += 1
    result += str(count) + c
    i += count
print(result)

💡 Run-length encoding: วนลูปนับจำนวนตัวอักษรที่เหมือนกันติดต่อกัน แล้วเขียนจำนวน+ตัวอักษร

🐍 main.py

กด Run เพื่อรันโค้ด หรือ ตรวจคำตอบ เพื่อตรวจ test cases