zgjja


私信TA

用户名:zgjja

访问量:10621

签 名:

X_X

等  级
排  名 147
经  验 7074
参赛次数 0
文章发表 71
年  龄 0
在职情况 学生
学  校
专  业 X_X

  自我简介:

TA的其他文章

两种方法(C++)
浏览:82

解题思路:

注意事项:

参考代码:

n, times, cnt, res = input(), int(input()), 1, ''
for i in range(times):
    res = ''
    if len(n) == 1:
        res += '1' + str(n)
    else:
        for j in range(len(n) - 1):
            if n[j] == n[j + 1]:
                cnt += 1
            else:
                res += str(cnt) + n[j]
                cnt = 1
        # if the last one is different from the previous one
        res += str(1) + n[-1] if n[-1] != n[-2] else ''
        # if the last one is the same as the previous one
        res += str(cnt) + n[0] if cnt != 1 else ''
    n = res
print(res)


 

0.0分

3 人评分

  评论区