题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import sys def childStr(attr): num_attr_list = [] s = len(attr) while s > 2: for i in range(len(attr)-1): if i+s <= len(attr)-1: num_attr_list.append(attr.count(attr[i:i+s])) s -= 1 for i in num_attr_list: if i > 1: return 'NG' return 'OK' def statType(attr): type_dict = { 'num': 0, 'LT': 0, 'lt': 0, 'other': 0 } for i in attr: if 48 <= ord(i) <= 57: type_dict['num'] += 1 elif 97 <= ord(i) <= 122: type_dict['lt'] += 1 elif 65 <= ord(i) <= 90: type_dict['LT'] += 1 else: type_dict['other'] += 1 count = 0 for j in type_dict.values(): if j != 0: count += 1 if count >= 3: return childStr(attr) #准备插入另外一个函数 else: return 'NG' def ngfunc(attr): if len(attr) < 8: return 'NG' for i in attr: if ord(i) == 32 or ord(i) == 10: return 'NG' return statType(attr) for line in sys.stdin: line = line.replace('\n', '') print(ngfunc(line))