1.题目

输入样例1:
13 1 2 3 4 5 6 7 8 9 10 20 16 18
输出样例1:
30 11 2 9.7 9
输入样例2:
8 1 2 4 5 6 7 9 16
输出样例2:
N 11 2 N 9
2.代码如下
# 本题可以分别定义五个函数,每个函数对应一个要求
lst = list(map(int, input().split()))[1:]
def A1(lst1):
sum1 = 0
for i in lst1:
if i % 5 == 0 and i % 2 == 0:
sum1 += i
if sum1 == 0:
return "N"
else:
return sum1
def A2(lst2):
sum2 = 0
count = 1
for i in lst2:
if i % 5 == 1 and count % 2 == 1:
sum2 += i
count += 1
elif i % 5 == 1 and count % 2 == 0:
sum2 -= i
count += 1
if count == 1:
return "N"
else:
return sum2
def A3(lst3):
count = 0
for i in lst3:
if i % 5 == 2:
count += 1
if count == 0:
return "N"
else:
return count
def A4(lst4):
count = 0
sum4 = 0
for i in lst4:
if i % 5 == 3:
sum4 += i
count += 1
if count == 0:
return "N"
else:
return round(sum4 / count, 1)
def A5(lst5):
max5 = -1
for i in lst5:
if i % 5 == 4 and i > max5:
max5 = i
if max5 == -1:
return "N"
else:
return max5
print(A1(lst), A2(lst), A3(lst), A4(lst), A5(lst))
3.提交结果


1324

被折叠的 条评论
为什么被折叠?



