有人能告诉我为什么我要在CodeChef上获得以下解决方案的WA吗?
问题链接:https://www.codechef.com/problems/TWTCLOSE
解决方案:
n, k = map(int, input().split())
com = []
while(k):
k -= 1
com.append(input())
l = len(com)
tweets = []
for i in range(0, n):
tweets.append(False)
for i in range(0, l):
if(com[i] == "CLOSEALL"):
for j in range(0, n):
tweets[j] = False
else:
temp = com[i]
tweets[int(temp[-1])-1] = not tweets[int(temp[-1])-1]
count = 0
for i in range(0, n):
if(tweets[i]):
count += 1
print(count)输入:
3 6
CLICK 1
CLICK 2
CLICK 3
CLICK 2
CLOSEALL
CLICK 1输出:
1
2
3
2
0
1发布于 2018-07-16 17:25:27
for i in range(0, l):
tweets.append(False) 这是错误的,有N条推特,我只是点击量。
if(com[i] == "CLOSEALL"):
for j in range(0, l):
tweets[j] = False因为同样的原因而错了。
for i in range(0, l):
if(tweets[i]):
count += 1再说一遍,只是数到l,而不是N。事实上,你根本就不用n。这是一个很大的暗示,你错过了什么。
更正后的更新:
tweets[int(temp[-1])-1] = not tweets[int(temp[-1])-1]temp-1指的是最后一个字符,这对于点击1到9的tweet是很好的,但是如果你想点击tweet 21,你只需要选择最后一个字符,所以你只需要点击tweet 1而不是21。按空格分割并选择所有的数字将是修复它的一种方法。
https://stackoverflow.com/questions/51363584
复制相似问题