20分求大佬帮调,样例输出是对的
查看原帖
20分求大佬帮调,样例输出是对的
1498425
nrZZZ777楼主2024/10/10 16:17
# 读取第一行字符串并去除两端空白
line = input().strip()
n = len(line)
text = line

# 继续读取剩余的n-1行字符串并连接,同时去除两端空白
for i in range(1, n):
    text += input().strip()

# 初始化变量
number = text[0]
lt_print = [n]
count = 1

# 统计连续相同字符的数量
for i in range(1, len(text)):
    if text[i] == number:
        count += 1
    else:
        number = text[i]
        lt_print.append(count)
        count = 1
lt_print.append(count)
# 输出结果
print(' '.join(map(str, lt_print)))
2024/10/10 16:17
加载中...