借助zlib.decompress()方法,我们可以使用字符串的压缩字节解压缩为原始字符串zlib.decompress()方法
用法:
zlib.decompress(string)返回:
Return decompressed string
范例1:
在这个例子中,我们可以通过使用zlib.decompress(s)
方法,我们可以使用此方法以字符串的字节格式解压缩压缩的字符串。
# import zlib and decompress
import zlib
s = b'This is GFG author, and final year student.'
# using zlib.compress(s) method
t = zlib.compress(s)
print("Compressed String")
print(t)
print("\nDecompressed String")
print(zlib.decompress(t))
输出:
Compressed String
b’x\x9c\x0b\xc9\xc8,V\x00″w7w\x85\xc4\xd2\x92\x8c\xfc”\x1d\x85\xc4\xbc\x14\x85\xb4\xcc\xbc\xc4\x1c\x85\xca\xd4\xc4″\x85\xe2\x92\xd2\x94\xd4\xbc\x12=\x00A\xc9\x0f\x0b’Decompressed String
b’This is GFG author, and final year student.’
范例2:
# import zlib and decompress
import zlib
s = b'GeeksForGeeks@12345678'
# using zlib.compress(s) method
t = zlib.compress(s)
print("Compressed String")
print(t)
print("\nDecompressed String")
print(zlib.decompress(t))
输出:
Compressed String
b’x\x9csOM\xcd.v\xcb/r\x07\xd1\x0e\x86F\xc6&\xa6f\xe6\x16\x00X\xf6\x06\xea’Decompressed String
b’GeeksForGeeks@12345678′
洛谷 P1000 超级玛丽游戏
题目背景
本题是洛谷的试机题目,可以帮助了解洛谷的使用。
另外强烈推荐新用户必读贴
题目描述
超级玛丽是一个非常经典的游戏。请你用字符画的形式输出超级玛丽中的一个场景。
******** ************ ####....#. #..###.....##.... ###.......###### ### ### ........... #...# #...# ##*####### #.#.# #.#.# ####*******###### #.#.# #.#.# ...#***.****.*###.... #...# #...# ....**********##..... ### ### ....**** *****.... #### #### ###### ###### ############################################################## #...#......#.##...#......#.##...#......#.##------------------# ###########################################------------------# #..#....#....##..#....#....##..#....#....##################### ########################################## #----------# #.....#......##.....#......##.....#......# #----------# ########################################## #----------# #.#..#....#..##.#..#....#..##.#..#....#..# #----------# ########################################## ############
import zlib,base64;
print(zlib.decompress(base64.b64decode('eJylUkEOwCAIu/sKk95Mxv+fN2AsE0S3xR42sRYqUqtHM5TJfsaBQQyQZ3jTGLp+JcqIjBUMSUMYy1Z6EB1J0hCOrhuywnoeXo4gF5U1I0nxJhc3rKSmH2vDd/Ny+nkMa6I3F7xmallrgvRh0K9L4DzLPLZQ9IY2CdekTKNjwK/qqdwK4J7TeZSa/wxtWKjc3W4VjdKdqt2tsIp2q3Y4AbV3oO4=')).decode())