鱼C论坛

 找回密码
 立即注册
查看: 1803|回复: 4

[已解决]间谍译码

[复制链接]
发表于 2022-4-11 20:42:48 From FishC Mobile | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
大神们帮帮忙我sololearn的一个 python题目,求帮忙,要求是英文的,要求如下:
You are a secret agent, and you receive an encrypted message that needs to be decoded. The code that is being used flips the message backwards and inserts non-alphabetic characters in the message to make it hard to decipher.

Task:
Create a program that will take the encoded message, flip it around, remove any characters that are not a letter or a space, and output the hidden message.

Input Format:  
A string of characters that represent the encoded message.

Output Format:
A string of character that represent the intended secret message.

Sample Input:
d89%l++5r19o7W *o=l645le9H

Sample Output:
Hello World
最佳答案
2022-4-11 21:13:43
阿育王 发表于 2022-4-11 21:09
有没有更常规的解法呢?

  1. s = "d89%l++5r19o7W *o=l645le9H"
  2. result = ""
  3. for i in s[::-1]:
  4.     if "a" <= i <= "z" or "A" <= i <= "Z" or i == " ":
  5.         result += i
  6. print(result)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-4-11 21:03:46 | 显示全部楼层
  1. import re
  2. s = "d89%l++5r19o7W *o=l645le9H"
  3. print(re.sub(r"[^a-zA-Z ]", "", s[::-1]))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-4-11 21:09:00 From FishC Mobile | 显示全部楼层
isdkz 发表于 2022-4-11 21:03

有没有更常规的解法呢?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-4-11 21:13:43 | 显示全部楼层    本楼为最佳答案   
阿育王 发表于 2022-4-11 21:09
有没有更常规的解法呢?

  1. s = "d89%l++5r19o7W *o=l645le9H"
  2. result = ""
  3. for i in s[::-1]:
  4.     if "a" <= i <= "z" or "A" <= i <= "Z" or i == " ":
  5.         result += i
  6. print(result)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-4-11 21:20:59 From FishC Mobile | 显示全部楼层
isdkz 发表于 2022-4-11 21:03

大神,求加微信好友哇本人微信号553915465
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-29 08:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表