密码要求:

1.长度超过8位

2.包括大小写字母.数字.其它符号,以上四种至少三种

3.不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行)

输入描述:

一组字符串。

输出描述:

如果符合要求输出:OK,否则输出NG

import sysimport redef has_repeated_substring(s, min_length):n = len(s)for i in range(n - min_length + 1):for j in range(i + 1, n - min_length + 1):# 检查长度大于等于 min_length 的子串是否相同if s[i:i + min_length] == s[j:j + min_length]:return 'OK'return 'NG'def password_demand(s):pattern = r'^(?:(?=.*[a-z])(?=.*[A-Z])(?=.*\d)|(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])|(?=.*[a-z])(?=.*\d)(?=.*[^a-zA-Z0-9])|(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9])).*$'if len(s)>8 and re.match(pattern,s) and has_repeated_substring(s,3)=='NG':result = 'OK'else:result = 'NG'return result for line in sys.stdin:a = line.strip()result = password_demand(a)print(result)