2020/03/01

[zerojudge] d139: Compressed String

from sys import stdin

for s in stdin:
    s = s.strip()
    ans = ''
    while(s):
        原長度 = len(s)
        c = s[0]  # 第一個字元
        s = s.lstrip(c)
        新長度 = len(s) 
        長度差 = 原長度 - 新長度
        if(長度差 < 3):
            ans += c * 長度差        
        else:
            ans += '{}{}'.format(長度差, c)
    print(ans)

沒有留言:

張貼留言