1012 数字分类 (20 point(s))

本文深入探讨了一种数字分类算法,该算法将输入的数字序列按照特定的数学规则进行分类处理,包括对数字的正负性、除以5的余数类别进行分析,计算各类别下数字的总和、平均值及最大值等关键信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



这个拿到了19分。。。错误还未找到


# 1012 数字分类 (20 point(s)) ipt1 = input().split(" ") ipt2 = ipt1[1:]

ipt1 = input().split(" ")
ipt2 = ipt1[1:]

s = 1   #标记正负号
result1 = 0
result2 = 0
result3 = 0
list4 = []
result4 = 0
list5 = []
result5 = 0

for i in ipt2:
    i = int(i)
    if i%5 == 0 and i%2 == 0:
        result1 = result1 + i
    if i%5 == 1:
        result2 = result2 + i*s
        s = -1*s
    if i%5 == 2:
        result3 = result3 + 1
    if i%5 == 3:
        list4.append(i)
    if i%5 == 4:
        list5.append(i)
try:
    result4 = round(sum(list4)/len(list4),1)
except:
    pass
if list5 != []:
    result5 = max(list5)
else:
    pass
if result1 == 0:
    result1 = "N"
if result2 == 0:
    result2 = "N"
if result3 == 0:
    result3 = "N"
if result4 == 0:
    result4 = "N"
if result5 == 0:
    result5 = "N"
print(result1,result2,result3,result4,result5)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值