爱奇艺8.23笔试
早上被字节虐惨了,在爱奇艺找回点自信吧
第一题
def CountZero(n): count = 0 while n > 0: n = n // 5 count += n return count if __name__ == '__main__': n = int(input().strip()) ans = CountZero(n) print(ans)
第二题
def solve(lu):
old = [(0, 0)]
for i in range(len(lu)):
pos = old[-1]
if lu[i] == 'N':
a, b = pos[0] - 1, pos[1]
old.append((a, b))
elif lu[i] == 'S':
a, b = pos[0] + 1, pos[1]
old.append((a, b))
elif lu[i] == 'E':
a, b = pos[0], pos[1] + 1
old.append((a, b))
elif lu[i] == 'W':
a, b = pos[0], pos[1] - 1
old.append((a, b))
if len(old) == len(set(old)):
return False
return True
if __name__ == '__main__':
lu = input().strip()
ans = solve(lu)
if ans:
print("True")
else:
print("False")
第三题
import collections
def solve(s):
stack = collections.deque()
for i in range(len(s)):
if s[i] == '('&nbs***bsp;s[i] == '{'&nbs***bsp;s[i] == '[':
stack.append(s[i])
else:
if len(stack) > 0:
p = stack.pop()
if (s[i] == ')' and p=='(')&nbs***bsp;(s[i] == '}' and p=='{')&nbs***bsp;(s[i] == ']' and p=='[') :
continue
else:
return False
else:
return False
return True
if __name__ == '__main__':
s = input().strip()
if solve(s):
print("True")
else:
print("False")
查看15道真题和解析