Love丶FFC's Blog

PAT乙级:1033 旧键盘打字

2020-02-23 11:47:37
阅读:604   •   评论:10
标签:,

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?

输入格式:

输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 10​5​​ 个字符的串。可用的字符包括字母 [a-zA-Z]、数字 0-9、以及下划线 _(代表空格)、,.-+(代表上档键)。题目保证第 2 行输入的文字串非空。

注意:如果上档键坏掉了,那么大写的英文字母无法被打出。

输出格式:

在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。

输入样例:

7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst

编程语言:Python

解题思想:

1.将实际输入的文字中的坏键替换掉

2.针对坏键中的英文字母,将实际输入的文字中的该字母及其大写字母替换掉

3.如果坏键中有+键,则将实际输入的文字中的所有大写字母替换掉

时间复杂度:O(N)

代码如下:

  1. DamageKey = list(input()) # 将每个坏键存放为列表元素
  2. RealKey = input() # 实际输入的文字
  3.  
  4. for i in range(len(DamageKey)): # 遍历每个坏键元素
  5. RealKey = RealKey.replace(DamageKey[i], '') # 将对应的坏键替换为空
  6. if str(DamageKey[i]).isalpha(): # 如果坏键是字母
  7. RealKey = RealKey.replace(str(DamageKey[i]).upper(), '') # 将该字母的大写替换掉
  8. RealKey = RealKey.replace(str(DamageKey[i]).lower(), '') # 将该字母的小写替换掉
  9.  
  10. if '+' in DamageKey: # 上档键也是坏键
  11. for i in range(len(RealKey)): # 逐个遍历实际输入的文字
  12. if str(RealKey[i]).isupper(): # 如果该文字是大写
  13. RealKey = RealKey.replace(str(RealKey[i]), '#') # 将该文字暂时替换为#号,如果直接替换为空,会导致字符串长度改变,导致循环条件错误
  14. RealKey = RealKey.replace('#', '') # 再将#替换为空
  15.  
  16. print(RealKey)

评论板

共有 10 条评论

  1. 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. exactly like the I will definitely continue to buy from this site. no matter what I will recommend this site to my friends. Thanks!
    original louis vuittons outlet https://www.bestlouisvuittonoutlet.com/

  2. cheap louis vuitton handbags

    I just wanted to thank you for the fast service. and it could be they look great. I received them a day earlier than expected. choose the I will definitely continue to buy from this site. in any event I will recommend this site to my friends. Thanks!
    cheap louis vuitton handbags https://www.louisvuittonsoutletstore.com/

  3. original louis vuittons outlet

    I just wanted to thank you for the fast service. or possibly a 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!
    original louis vuittons outlet https://www.cheapreallouisvuitton.com/

  4. jordans for cheap

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

  5. Gealpaste

    where to buy cialis online safely Paratesticular desmoplastic small round cell tumors A case report and review of the literature

  6. authentic cheap jordans

    Read reviews and was a little hesitant since I had already inputted my order. quite possibly but thank god, I had no issues. prefer 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.
    authentic cheap jordans https://www.cheapauthenticjordanshoes.com/

  7. cheap retro jordans

    Read reviews and was a little hesitant since I had already inputted my order. or 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.
    cheap retro jordans https://www.cheaprealjordan.com/

  8. cheap louis vuitton

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

  9. authentic cheap jordans

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

  10. intuido

    image levitra The marked limbal cells did not contribute to the maintenance regeneration of the cornea, but the marked corneal epithelium did so Fig

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

已运行:

访问量:454815