Love丶FFC's Blog

PAT乙级:1023 组个最小数

2020-02-14 09:34:57
阅读:3951   •   评论:29
标签:,

给定数字 0-9 各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意 0 不能做首位)。例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就是 10015558。

现给定数字,请编写程序输出能够组成的最小的数。

输入格式:

输入在一行中给出 10 个非负整数,顺序表示我们拥有数字 0、数字 1、……数字 9 的个数。整数间用一个空格分隔。10 个数字的总个数不超过 50,且至少拥有 1 个非 0 的数字。

输出格式:

在一行中输出能够组成的最小的数。

输入样例:

2 2 0 0 0 3 0 0 1 0

输出样例:

10015558

编程语言:Python

解题思想:

本题可以利用比较巧妙的解法

1.例如样例所给的2 2 0 0 0 3 0 0 1 0

2.先用列表存放[1,1,5,5,5,8]

3.再将0插入到第一个1后面,即[1,0,0,1,5,5,5,8]

4.再将每一位用字符串连接起来

5.最终把字符串转为整型

时间复杂度:O(N)

代码如下:

  1. Number = list(map(int, input().split())) # 存放0-9的数字的个数
  2. NumberList = list() # 存放1-9的数字
  3.  
  4. for i in range(1, 10):
  5. NumberList += [i for j in range(Number[i])] # 添加j个数字i,例如有3个2,则将3个2都添加到NumberList中
  6.  
  7. NumberList = NumberList[0:1] + [0 for i in range(Number[0])] + NumberList[1:] # 列表拼接,如果有0,在第一个数后面添加0
  8.  
  9. Min = ''
  10. for i in range(len(NumberList)):
  11. Min += str(NumberList[i]) # 字符串连接
  12.  
  13. print(int(Min))

评论板

共有 29 条评论

  1. Abupguele

    cheapest cialis Truong PT, Lee J, Kader HA, et al Locoregional recurrence risks in elderly breast cancer patients treated with mastectomy without adjuvant radiation therapy

  2. fruinly

    You need to get on with everyday life, prepare for events, take care of loved ones and pay those bills nolvadex on sale usa PMID 32645509

  3. Outlils

    5737 CYP450 3A4 inhibitor Non inhibitor 0 cialis online pharmacy With the prices and the 400 min I m inclined to look elsewhere

  4. original louis vuittons outlet

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

  5. louis vuitton outlet

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

  6. cheap real jordans

    I just wanted to thank you for the fast service. as well they look great. I received them a day earlier than expected. which include the I will definitely continue to buy from this site. you ultimately choose I will recommend this site to my friends. Thanks!
    cheap real jordans https://www.realcheapretrojordanshoes.com/

  7. louis vuitton outlet

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

  8. cheap jordans online

    I just wanted to thank you for the fast service. while well as they look great. I received them a day earlier than expected. the same as I will definitely continue to buy from this site. situation I will recommend this site to my friends. Thanks!
    cheap jordans online https://www.cheaprealjordan.com/

  9. FoorryNox

    Using a strict definition of treatment success in our study, success rate with tamoxifen was 65 buying cialis online usa Treatment with TMX might be complementary to and synergistic with other new therapeutic agents such as those acting on the CFTR defect and trafficking, and or those inhibiting epithelial sodium channel activity

  10. cheap jordans for sale

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

  11. cheap retro jordans

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

  12. cheap jordans for sale

    Read reviews and was a little hesitant since I had already inputted my order. or maybe but thank god, I had no issues. much like the received item in a timely matter, they are in new condition. no matter what so happy I made the purchase. Will be definitely be purchasing again.
    cheap jordans for sale https://www.realjordansshoes.com/

  13. louis vuitton outlet

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

  14. invoimi

    the abdominal bloat i think is definately from diet and possibly that when all your body shrinks thanks to Aromasin, only thing that STANDS OUT is your belly abdominal how much does cialis cost aceon cefixime dispersible tablets 200mg in hindi However, Catton said she was glad that the changes removed the artificial restrictions of nationality from the prize, echoing assertions from Man Booker organizers that the award will become the world s biggest English language fiction award

  15. invoimi

    A drop of sample diluted with water was placed on a copper grid and the excess was drawn off with a filter paper buy fincar 5mg cheap During a hysterectomy, your doctor may remove the entire uterus or just part of it

  16. Preliaf

    Less frequent cardiac manifestations include dynamic LV outflow obstruction, often confused with hypertrophic cardiomyopathy; cardiac ischemia caused by amyloid deposition in intramural coronary arteries; and intracardiac thrombosis caused by atrial wall standstill, with a risk for systemic embolization adderall and viagra Cardiac function should be regularly assessed during treatment

  17. why are likes disappearing on instagram

    hello there and thank you for your info – I’ve certainly picked up something new from right here.
    I did however expertise several technical points using this web site,
    as I experienced to reload the web site many times previous to I could get it
    to load correctly. I had been wondering if your web host is OK?
    Not that I’m complaining, but slow loading instances times
    will very frequently affect your placement in google and can damage your quality score if advertising and
    marketing with Adwords. Anyway I’m adding this RSS to my email and can look out for a lot more of
    your respective interesting content. Make sure you update this again soon.

  18. buy real followers instagram 2021

    Good blog post. I absolutely appreciate this website.
    Keep writing!

  19. can you buy real tiktok followers?

    Amazing blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really
    make my blog jump out. Please let me know where you got your theme.
    Kudos

  20. where to buy nigeria instagram followers

    Hey there this is somewhat of off topic but I was wanting to know if
    blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding experience so I wanted to get guidance from someone with experience.
    Any help would be greatly appreciated!

  21. buy instagram followers for a dollar

    I take pleasure in, cause I discovered just what I was looking for.
    You’ve ended my four day lengthy hunt! God Bless you man. Have a nice day.
    Bye

  22. buy instagram followers uk

    Hi! Do you know if they make any plugins to assist with Search Engine Optimization? I’m
    trying to get my blog to rank for some targeted keywords but I’m not seeing very good results.

    If you know of any please share. Cheers!

  23. EZFyFWUj

    7; N 42; Supplementary Fig buy cialis online us 73; P In the United Kingdom International Study NCT00112931, 379 previously untreated patients with asymptomatic, low burden disease were randomly assigned to watchful waiting versus rituximab induction only versus rituximab induction followed by 2 years of rituximab maintenance

  24. takasi4d

    Having read this I thought it was rather enlightening. I appreciate you spending some
    time and energy to put this informative article together.
    I once again find myself personally spending a significant amount of time
    both reading and posting comments. But so what, it was still worth it!

  25. detailing

    Hi, everything is going well here and ofcourse every
    one is sharing data, that’s actually good, keep up writing.

  26. How I Earned $25 Online in One Day Using Ezoic: A Success Story

    Thank you, I have recently been looking for info approximately this subject for a while and yours is the best I’ve came upon till now.

    However, what concerning the bottom line? Are you positive about the supply?

  27. logiciel crm définition

    Ce contenu pertinent a vraiment éveillé mon attention. En tant que
    responsable des ventes, je suis constamment à la
    recherche de nouvelles stratégies pour booster les performances.
    J’ai trouvé beaucoup de contenu sur les CRM qui semblent vraiment optimiser la gestion des prospects.

  28. movie

    Hi everyone, it’s my first pay a visit at this site, and paragraph is truly fruitful for me, keep up posting
    such posts.

  29. tqjZNS

    Our deepest sympathies to all of the Kroetch families achat levitra en bretagne

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名: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 -

已运行:

访问量:451272