題目描述
密碼要求:
1.長度超過8位
2.包括大小寫字母.數字.其它符號,以上四種至少三種
3.不能有相同長度超2的子串重複
說明:長度超過2的子串
輸入描述:
一組或多組長度超過2的子符串。每組佔一行
輸出描述:
如果符合要求輸出:OK,否則輸出NG
解法1(Python3):
import re
import sys
for line in sys.stdin:
line = line.strip()
if len(line) <= 8:
print('NG')
continue
count = 0
if re.search('[a-z]+', line) is not None:
count += 1
if re.search('[A-Z]+', line) is not None:
count += 1
if re.search('[0-9]+', line) is not None:
count += 1
if re.search('[^a-zA-Z0-9]+', line) is not None:
count += 1
if count < 3:
print('NG')
continue
for i in range(len(line)-3):
if line.count(line[i:i+3]) > 1:
print('NG')
break
else:
print('OK')
解法2(Python3):
import re
try:
while True:
s = input()
a = re.findall(r'.*(.{3,}).*\1', s)
b1 = re.findall(r'[0-9]', s)
b2 = re.findall(r'[A-Z]', s)
b3 = re.findall(r'[a-z]', s)
b4 = re.findall(r'[^0-9A-Za-z]', s)
if [b1, b2, b3, b4].count([]) <= 1 and a == [] and len(s) > 8:
print('OK')
else:
print('NG')
except:
pass