程序a | 程序b |
a = 2 res = 1 n = int(input()) for i in range(n): res = res * a print(res) | def powr(a, n): if n == 1: return a elif n == 0: return 1 else: tmp = powr(a, n // 2) return tmp * tmp a = 2 n = int(input()) print(powr(a, n)) |
import random
n = 8
a = [random.randint(0, 9)
for i in range(n)]
for t in range(2):
i = t + 1
while i < n-1:
if t % 2 == 0:
if a[i-1] < a[i] and a[i] > a[i+1]:
i += 2
else:
a[i] += random.randint(0, 9)
else:
if a[i-1] > a[i] and a[i] < a[i+1]:
i += 2
else:
a[i] = random.randint(0, 9)
运行后,数组a中的值可能是( )
n = 5; head = 0
a = [[None, 1], [50, 2], [30, 3], [10, 4], [20, 5], [30, -1]]
for i in range(n-1):
r = head
p = a[r][1]
q = a[p][1]
while q != -1:
if a[p][0] > a[q][0]:
a[r][1] = q
①
a[q][1] = p
r = a[r][1]
p = a[r][1]
②
# 从head指针的下一个节点开始输出链表,结果为有序序列,代码略
划线处应该填写的语句是( )