PAT 1012 数字分类 (Python代码)

origin_num = [int(x) for x in input().split()]
result_num = ['N','N','N','N','N']
mod1_num = []
sum1,sum2,sum3,count2,count3,max = 0,0,0,0,0,0

for i in range(1,len(origin_num)):
    if origin_num[i] % 5 == 0 and origin_num[i] % 2 == 0:
        sum1 += origin_num[i]
        result_num[0] = sum1
    elif origin_num[i] % 5 == 1:
        mod1_num.append(origin_num[i])
    elif origin_num[i] % 5 == 2:
        count2 += 1
        result_num[2] = count2
    elif origin_num[i] % 5 == 3:
        sum3 += origin_num[i]
        count3 += 1
        result_num[3] = round((sum3/count3),1)
    elif origin_num[i] % 5 == 4:
        if max < origin_num[i]:
            max = origin_num[i]
        result_num[4] = max
if len(mod1_num) % 2 == 1:
    mod1_num.append(0)
for i in range(0,len(mod1_num)-1,2):
    sum2 += (mod1_num[i] - mod1_num[i+1])
    result_num[1] = sum2
for i in range(0,5):
    if i == 4:
        print(result_num[i],end='')
    else:
        print(result_num[i],end=' ')

输入数据的第一个数为输入的个数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值