python代码,一直RE,大佬求助

P1320 压缩技术(续集版)

vexento @ 2022-07-04 09:17:50

s = list()
s.append(input())
tl = len(s[0])
for i in range(tl-1):
    s.append(input())
print("%d " % tl, end="")
cnt = 0
last = -1
s = "".join(s)
for i in range(len(s)):
    if last == -1 or last == int(s[i]):
        cnt += 1
    else:
        print("%d " % cnt, end="")
        cnt = 1
    last = int(s[i])
print("%d " % cnt, end="")

by Terrible @ 2022-07-04 09:40:45

@vexento

input()换成input().strip(),就没有RE了。


by Terrible @ 2022-07-04 09:42:07

数据每行末尾可能带有\r

常见“我在本地/xxOJ AC了、洛谷却不过”的原因


by vexento @ 2022-07-04 15:36:00

@Terrible 已过,多谢大佬!


by vvipi @ 2022-07-09 20:43:49

感谢解析,我也是因为这个原因一直RE。


by gan_chun_A @ 2022-09-02 18:51:34

@Terrible 太感谢了,一直是这个原因


by Luc_002 @ 2023-04-26 17:33:06

@Terrible 感谢~~~


|