商汤科技2018校招 [编程题]解码
dp,注意'0'字符的处理
def solver(s, n):
if n == 1: return 1
dp = [1] * n
if s[1] != '0' and (s[0] == '1' or (s[0] == '2' and s[1] <= '6')):
dp[1] = 2
else:
dp[1] = 1
for i in range(2, n):
if s[i] != '0' and (s[i - 1] == '1' or (s[i - 1] == '2' and s[i] <= '6')):
dp[i] = dp[i - 1] + dp[i - 2]
else:
dp[i] = dp[i - 1]
return dp[n - 1]
s = input().strip()
n = len(s)
if s[0] == '0' or '00' in s: ans = 0
else: ans = solver(s, n)
print(ans)
浙公网安备 33010602011771号