题解 | #字符串加密#

字符串加密

http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3

while True:
    try:
        key_word = input()
        string_in = input()
        new_key=[]
        letterlst = []
        string_out =''
        for i in range(26):
            letterlst.append(chr((ord("a")+i)))
        for word in key_word:
            if word not in new_key:
                new_key.append(word)
        for letter in new_key:
            letterlst.remove(letter)
        new_key.extend(letterlst)
        for str in string_in:
            if str.isalpha():
                index= ord(str)-97
                string_out+=new_key[index]
            else:
                string_out+=str
        print(string_out)
        
    except:
        break

重点几个python function:

  1. ord("a") 根据给定的character 返回Unicode code (ord("a")=97)
  2. chr() 参数是一个范围在255内的整数,返回对应的字符 (chr()和ord()可以看作互逆的函数)
全部评论

相关推荐

头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
身边有人上海、深圳 6、7k 都去了,真就带薪上班了。
程序员小白条:木的办法, 以后越来越差,还是家附近宅着吧,毕业的人越来越多,岗位都提供不出来,经济又过了人口红利期
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务