def is_pamax(name): low = 0 up = len(name)-1 while low < up: if name[low] != name[up]: return False low += 1 up -= 1 return True f = open("D:/names.txt") max_length = 0 for line in f: name = line.strip() if is_pamax(name): temp_length = len(name) if temp_length > max_length: max_length=temp_length print max_length f.close() # maxlength=8 f = open("D:/names.txt") for line in f: name = line.strip() if is_pamax(name): if 8 == len(name): print name f.close()
时间: 2024-10-07 02:37:41