Python-CCF:20180901 卖菜

文章目录

题目描述

在这里插入图片描述

用时

写代码用了十分钟,debug了四十分钟
???
天杀的CCF
用Python的同学注意了
split(' ')作输入的分割可能有坑
如果题目描述没有明确的说输入是用空格分割的那么就不要用split(' ')
种苹果那道题说了
在这里插入图片描述而卖菜这道没说
没说的话测试用例有可能是用其他的空白字符分割的
这时用split(' ')就分割不了了
所以统一换用split(),以任意的空白字符进行分割
我真是服了
在这里插入图片描述

代码

if __name__ == "__main__":
    store_num = int(input())
    first_prices = list(map(int, input().split()))
    second_prices = []

    second_prices.append(int((first_prices[0] + first_prices[1]) / 2))
    for store_no in range(1, store_num-1):
        second_prices.append(int((first_prices[store_no-1] + first_prices[store_no] + first_prices[store_no+1]) / 3))
    second_prices.append(int((first_prices[-1] + first_prices[-2]) / 2))

    for sp in second_prices:
        print(sp, end=' ')

发布了61 篇原创文章 · 获赞 11 · 访问量 4845

猜你喜欢

转载自blog.csdn.net/weixin_43249758/article/details/104412862