@StarSky
2017-07-12T06:23:37.000000Z
字数 1090
阅读 1126
Puzzle
begin-> http://www.pythonchallenge.com/pc/def/0.html
# -*- coding: utf-8 -*-
"""1"""
"""http://www.pythonchallenge.com/pc/def/map.html"""
char_string = 'map'
new_string = ''
for char in char_string:
if char != '.' and char != ' ':
if ord(char) == 121:
new_string += 'a'
elif ord(char) == 122:
new_string += 'b'
else:
charcode = ord(char) + 2
new_char = chr(charcode)
new_string += new_char
else:
new_string += char
print(new_string)
"""2"""
"""http://www.pythonchallenge.com/pc/def/ocr.html"""
dict_test = {}
with open('/Users/saber/Desktop/untitled', 'r') as f:
for line in f.readlines():
for char in line:
if char not in dict_test:
dict_test[char] = 1
else:
dict_test[char] += 1
dict_test = sorted(dict_test.items(), lambda x, y: cmp(int(x[1]), int(y[1])))
print("pause")
"""3"""
"""http://www.pythonchallenge.com/pc/def/equality.html"""
with open('/Users/saber/Desktop/untitled', 'r') as f:
new_string = ''
for line in f.readlines():
for char in line:
if char.isupper():
if 0 < len(new_string) < 4:
new_string += char
elif 5 <= len(new_string) <= 7:
new_string += char
else:
new_string = ''
else:
if len(new_string) == 4:
new_string += char
elif len(new_string) == 8:
print new_string[4]
new_string = ''
else:
new_string = char