Love丶FFC's Blog

PAT乙级:1029 旧键盘

2020-02-19 10:36:44
阅读:7274   •   评论:153
标签:,

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。

输入格式:

输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 _(代表空格)组成。题目保证 2 个字符串均非空。

输出格式:

按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有 1 个坏键。

输入样例:

7_This_is_a_test
_hs_s_a_es

输出样例:

7TI

编程语言:Python

解题思想:

1.本质为求两集合的差集,但题目要求按发现的顺序进行输出,如果直接进行差集运算,差集的顺序会有不同

直接用差集运算无法保证顺序
直接用差集运算无法保证顺序

2.所以采用遍历的方法进行判断,题目又要求英文字母要转为大写输出,所以需要一个列表来存放转为大写后的字符

时间复杂度:O(N)

代码如下:

  1. Full = list(input()) # 应该输入的文字
  2. Part = set(list(input())) # 实际输入的文字,用集合去重
  3. Difference = list() # 存放Full与Part的差集
  4.  
  5. for i in range(len(Full)): # 遍历Full中的字符,判断是否存在于Part和差集中
  6. if Full[i] not in Part and str(Full[i]).upper() not in Difference: # 该字符及其大写第一次出现
  7. Difference.append(str(Full[i]).upper()) # 存放该字符的大写
  8.  
  9. for i in range(len(Difference)):
  10. print(Difference[i], end='')

评论板

共有 153 条评论

  1. 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.cheapreallouisvuitton.com/

  2. cheap louis vuitton handbags

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

  3. cheap jordans

    I just wanted to thank you for the fast service. in addition they look great. I received them a day earlier than expected. similar to the reduction I will definitely continue to buy from this site. blue jays I will recommend this site to my friends. Thanks!
    cheap jordans https://www.realcheapretrojordanshoes.com/

  4. authentic cheap jordans

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

  5. cheap jordan shoes

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

  6. authentic louis vuitton outlet

    Read reviews and was a little hesitant since I had already inputted my order. perhaps but thank god, I had no issues. significantly 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.
    authentic louis vuitton outlet https://www.louisvuittonsoutlet.com/

  7. cheap jordans for sale

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

  8. cheap louis vuitton handbags

    Read reviews and was a little hesitant since I had already inputted my order. on the other hand but thank god, I had no issues. for example the received item in a timely matter, they are in new condition. in any event so happy I made the purchase. Will be definitely be purchasing again.
    cheap louis vuitton handbags https://www.louisvuittonsoutletonline.com/

  9. FoorryNox

    I always recommend testing rather than guessing, and using hormones judiciously under the care of a medical provider knowledgable about them cheap cialis no prescription

  10. https://maps.google.ba/url?q=https://www.topoakleysoutlet.com/

    |You can have a dressy look by wearing black jeans and a nice blouse, with heels. If you’re wearing the latest trend, colored jeans, it’s best to go for a more casual look.

  11. Preliaf

    Several studies have indicated various mechanisms in tamoxifen resistance generic propecia AUB can be caused by pelvic pathology like a distortion of the endometrial cavity due to fibroids, or endometrial protrusions into the cervix or vagina polyps, or because of friable endometrial tissue

  12. xtMqNriJE

    can you mix viagra and sleeping pills I had cataract surgery in one eye, and 4 months out, good results

  13. Bnxtoi

    tricor 200mg brand generic fenofibrate buy tricor for sale

  14. Wceoaq

    tadalafil 10mg drug buy viagra 100mg pill viagra sildenafil 50mg

  15. Mknred

    order mintop solution flomax where to buy buying ed pills online

  16. Flaxnj

    ketotifen over the counter order zaditor 1 mg order tofranil 75mg

  17. Wxqyct

    brand aspirin 75 mg order lquin 250mg pill cost zovirax

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

已运行:

访问量:448321