Love丶FFC's Blog

PAT乙级:1092 最好吃的月饼

2020-04-24 10:52:35
阅读:1745   •   评论:20
标签:,

月饼是久负盛名的中国传统糕点之一,自唐朝以来,已经发展出几百品种。

mk.jpg

若想评比出一种“最好吃”的月饼,那势必在吃货界引发一场腥风血雨…… 在这里我们用数字说话,给出全国各地各种月饼的销量,要求你从中找出销量冠军,认定为最好吃的月饼。

输入格式:

输入首先给出两个正整数 N(≤1000)和 M(≤100),分别为月饼的种类数(于是默认月饼种类从 1 到 N 编号)和参与统计的城市数量。

接下来 M 行,每行给出 N 个非负整数(均不超过 1 百万),其中第 i 个整数为第 i 种月饼的销量(块)。数字间以空格分隔。

输出格式:

在第一行中输出最大销量,第二行输出销量最大的月饼的种类编号。如果冠军不唯一,则按编号递增顺序输出并列冠军。数字间以 1 个空格分隔,行首尾不得有多余空格。

输入样例:

5 3
1001 992 0 233 6
8 0 2018 0 2008
36 18 0 1024 4

输出样例:

2018
3 5

编程语言:Python

解题思想:

1.题目已经说明,输入的第i个整数为第i种月饼的销量

2.按照这一点,提前创建一个列表,并且把每个值都初始化为0

3.按照编号递增进行销量冠军的筛选

时间复杂度:O(N^2)

代码如下:

  1. NOM, NOC = map(int, input().split()) # 输入月饼种类的个数、参与统计的城市个数
  2. MoonCake = [0 for i in range(NOM)] # 存放每种月饼的销量
  3. ChampionID = list() # 存放销量最好的月饼的编号
  4.  
  5. for i in range(NOC):
  6. Sales = list(map(int, input().split()))
  7. for j in range(len(Sales)): # 遍历一行输入
  8. MoonCake[j] += Sales[j] # 增加对应索引的月饼销量
  9.  
  10. for i in range(NOM):
  11. if MoonCake[i] == max(MoonCake):
  12. ChampionID.append(i + 1) # 按照编号递增顺序,添加销量最好的月饼编号
  13.  
  14. print(max(MoonCake))
  15. for i in range(len(ChampionID)): # 按格式输出
  16. if i != len(ChampionID) - 1:
  17. print(ChampionID[i], end=' ')
  18. else:
  19. print(ChampionID[i])

评论板

共有 20 条评论

  1. authentic cheap jordans

    I just wanted to thank you for the fast service. and they look great. I received them a day earlier than expected. the same as the I will definitely continue to buy from this site. in either case I will recommend this site to my friends. Thanks!
    authentic cheap jordans https://www.realcheapretrojordanshoes.com/

  2. cheap louis vuitton outlet

    I just wanted to thank you for the fast service. and even they look great. I received them a day earlier than expected. exactly like the I will definitely continue to buy from this site. situation I will recommend this site to my friends. Thanks!
    cheap louis vuitton outlet https://www.bestlouisvuittonoutlet.com/

  3. cheap louis vuitton outlet

    I just wanted to thank you for the fast service. potentially they look great. I received them a day earlier than expected. enjoy the I will definitely continue to buy from this site. in either case I will recommend this site to my friends. Thanks!
    cheap louis vuitton outlet https://www.cheapreallouisvuitton.com/

  4. original louis vuittons outlet

    I just wanted to thank you for the fast service. or even a they look great. I received them a day earlier than expected. such I will definitely continue to buy from this site. you ultimately choose I will recommend this site to my friends. Thanks!
    original louis vuittons outlet https://www.louisvuittonsoutletstore.com/

  5. louis vuittons outlet

    Read reviews and was a little hesitant since I had already inputted my order. or even but thank god, I had no issues. love the received item in a timely matter, they are in new condition. you ultimately choose so happy I made the purchase. Will be definitely be purchasing again.
    louis vuittons outlet https://www.louisvuittonsoutlet.com/

  6. cheap jordans online

    Read reviews and was a little hesitant since I had already inputted my order. and even but thank god, I had no issues. choose to received item in a timely matter, they are in new condition. blue jays so happy I made the purchase. Will be definitely be purchasing again.
    cheap jordans online https://www.realjordansretro.com/

  7. louis vuittons outlet

    Read reviews and was a little hesitant since I had already inputted my order. maybe but thank god, I had no issues. particularly received item in a timely matter, they are in new condition. regardless so happy I made the purchase. Will be definitely be purchasing again.
    louis vuittons outlet https://www.louisvuittonsoutletonline.com/

  8. FoorryNox

    There are some lifestyle changes that can help you work through these changes, including generic cialis from india

  9. gucci.com sale handbags

    What is the recycling price of GUCCI’s “highest value” classic bags?

  10. cheap authentic

    $ 93.18Cheap Jordan 4 Women “Cement ash“

  11. classic gucci bags

    NO.3MK Whitney small shoulder bag ¥4300 MK This Whitney shoulder bag has simple lines and an adjustable chain strap. It is double-folded and suitable for commuting. The leather is made of rare lambskin, which is softer and more delicate than lambskin, and the metal buckle adds a sense of gorgeousness.

  12. gucci handbags outlet canada

    Sylvie1969 series is a series that is very suitable for commuting to work. 1969 is full of aura and full of business elites.

  13. Retro Air Jordan Shoes

    Cheap Jordan 11, Platinum Tint, for sale After seeing the real thing, it is planted! Cheap Jordan 11 “Platinum Tint” Appreciate your feet!

  14. barSosz

    Two patients experienced adverse events that required ceritinib dose reductions buy priligy

  15. Fvcahe

    buy tricor generic buy fenofibrate 160mg online order tricor online

  16. Qjbpcu

    order zaditor without prescription buy cheap generic ziprasidone tofranil 75mg without prescription

  17. Nlrslf

    order cialis 5mg generic sildenafil 100mg ca sildenafil next day

  18. Qqexqm

    precose pills order fulvicin 250 mg without prescription buy griseofulvin 250 mg generic

  19. Yuyoml

    buy minoxytop paypal tamsulosin 0.2mg canada ed pills

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:503322