0. 2**38
1. 字符串映射
s = """
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.
"""
def to(c):
return chr((ord(c)-ord('a') + 2) % 26+ord('a'))
def tos(s):
ss = ""
for i in s:
if i >= 'a' and i <= 'z':
ss += to(i)
else:
ss += i
return ss
print(tos("map"))
2. 字符串去重
s="""......"""
m = {}
for i in s:
if not i in m:
m[i] = 0
m[i] += 1
for i in s:
if m[i] == 1:
print(i,end="")
3. 正则表达式:三个大写字母包围的小写字母
- 要正好三个
- 要把满足条件的小写字母连起来
import requests
import re
resp = requests.get("http://www.pythonchallenge.com/pc/def/equality.html")
s = resp.text
s = s[s.index("<!--"):]
s = s[4:-4]
x = re.findall("[^A-Z][A-Z]{3}[a-z][A-Z]{3}[^A-Z]", s)
print("".join([i[4] for i in x]))
4. 网络请求+正则表达式,需要向服务器请求大约400次,中间会有一些中断,按照服务器要求来
当中断后,记录下中断前的那个数字,从那个数字接着来
因为这个游戏过于耗时(请求400次大约需要5分钟,并且中间偶尔会请求失败),所以参考别人的(答案为peak.html)
import re
import requests
s = 8022
cnt = 400
while cnt > 0:
cnt -= 1
resp = requests.get("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing={}".format(s))
ss = resp.text
print(cnt, ss)
s = re.search("[0-9]*$", ss)
if s == None: # 注意如果没有匹配项,返回None
break
s = s.group()
if len(s) == 0: # 因为上面是*,所以一定能够匹配上一个空串,所以这里必须判断len(s)
break
print(s)
5. pickle用于python持久化,然后发现这是一个由空格和井号组成的字符画
import pickle
import requests
s = requests.get("http://www.pythonchallenge.com/pc/def/banner.p").text
x = pickle.loads(bytes(s, encoding="utf8"))
print("
".join(["".join([i[0] * i[1] for i in row]) for row in x]))
6. zipfile包用于压缩解压缩
这个问题太含蓄了,改成y.html,有回复,但没用
title后面有注释zip,于是改为zip.html,有回复
改为channel.zip下载一个zip文件,查看readme,跟前面的网络请求那道题差不多
我在想,这道题怎么考查zipfile呢?原来这道题需要获取文件信息,将文件注释拼接起来才能得到一个字符画,解压之后就无法看见压缩的文件信息了。
import requests
import zipfile
import re
resp = requests.get("http://www.pythonchallenge.com/pc/def/channel.zip")
open("haha.zip", "wb").write(resp.content)
f = zipfile.ZipFile("haha.zip")
nothing = 90052
comments = ""
while 1:
filename = str(nothing) + ".txt"
x = f.read(filename)
s = str(x, "utf8")
comments += str(f.getinfo(filename).comment, "utf8")
print(s, comments)
s = re.search("d*$", s)
if s == None:
break
nothing = s.group()
if len(nothing) == 0:
break
print(nothing)
得到答案hockey(火箭),字符画使用oxygen拼起来的。url实际上就是oxygen