密码要求:
1.长度超过8位
2.包括:大写字母/小写字母/数字/其它符号,以上四种至少三种
3.不能分割出两个相等的长度大于 2 的子串,例如 abcabc 可以分割出两个 abc,不合法,ababa 则无法分割出2个aba。
注:其他符号不含空格或换行
数据范围:输入的字符串长度满足
密码要求:
1.长度超过8位
2.包括:大写字母/小写字母/数字/其它符号,以上四种至少三种
一组字符串。
如果符合要求输出:OK,否则输出NG
021Abc9000 021Abc9Abc1 021ABC9000 021$bc9000 021Abc1111
OK NG NG OK OK
while True: try: S = input() d, x, n, q = 0, 0, 0, 0 if len(S) < 8: print('NG') else: for s in S: if s.isupper() == True and d != 1: d = 1 elif s.islower() == True and x != 1: x = 1 elif s.isdigit() == True and n != 1: n = 1 elif s.isalnum() == True and s != ' ' and s != '\n' and q != 1: q = 1 if d + x + n + q < 3: print('NG') else: i = 3 pd = False while i < len(S) / 2: for j in range(len(S) - i): Sq = S[j:j + i] Sy = S[0:j] + S[j + i:] if Sq in Sy: pd = True break if pd == True: print('NG') break else: i += 1 if pd == False: print('OK') except: break
import re import sys for s in sys.stdin: flag=0 sign=set() if len(s)>8: flag+=1 for i in s: if i.isdigit(): sign.add("D") elif i.isupper(): sign.add("U") elif i.islower(): sign.add("L") elif not i.isalnum() and not i.isspace() and i!="\n": sign.add("S") if len(sign)>=3: flag+=1 if not re.findall(r"(.{3,}).*\1",s): flag+=1 print("OK" if flag==3 else "NG")
import sys def pwd_is_ok(): for line in sys.stdin: a = line.split() s = a[0] if is_len_8(s) and is_3_kinds_str(s) and is_repeat_str(s): print('OK') else: print('NG') def is_len_8(s): if len(s) < 8: return False return True def is_3_kinds_str(s): kind_count = 0 for x in s: if ord(x) in range(33, 47)&nbs***bsp;ord(x) in range(58, 64)&nbs***bsp;ord(x) in range(91, 95)&nbs***bsp;ord(x) in range(123, 126): kind_count += 1 if ord(x) in range(48, 57): kind_count += 1 if ord(x) in range(65, 90): kind_count += 1 if ord(x) in range(97, 122): kind_count += 1 if kind_count > 2: return True return False def is_repeat_str(s): tmp_list = list() for i in range(len(s)): if i < len(s) - 1: tmp_list.append(s[i:i+3]) # print(tmp_list, len(tmp_list)) # print(set(tmp_list), len(set(tmp_list))) if len(tmp_list) > len(set(tmp_list)): return False return True def main(): pwd_is_ok() if __name__ == '__main__': main()
while True: try: import re a = input() m, n, p, q = 0, 0, 0, 0 if len(a) > 8: for t in a: b1 = re.search("[a-z]", t) b2 = re.search("[A-Z]", t) b3 = re.search("[0-9]", t) b4 = re.search("[^a-zA-Z0-9]", t) if b1: m = 1 elif b2: n = 1 elif b3: q = 1 else: p = 1 if m + n + p + q >= 3: i = 0 k = 0 for i in range(len(a)): for j in range(i, len(a)): if a[i : j + 3] not in a[j + 3 : len(a)]: i += 1 else: k += 1 if k == 0: print("OK") else: print("NG") else: print("NG") else: print("NG") except: break
import sys passwords = list(sys.stdin.readlines()) def isValid(s:str) -> bool: if len(s) <= 8: return False # 检查第二个条件 a,b,c,d = 0,0,0,0 for ch in s: if ord("a") <= ord(ch) <= ord("z"): a = 1 elif ord("A") <= ord(ch) <= ord("Z"): b = 1 elif ord("0") <= ord(ch) <= ord("9"): c = 1 else: if ch not in [" ","\n"]: d = 1 if a+b+c+d <3: return False # 检查第三个条件 for i in range(len(s)-3+1): if len(s.split(s[i:i+3])) >=3: return False return True for password in passwords: if isValid(password): print("OK") else: print("NG")
import re while True: try: raw_strs = input() raw_set = "".join(set(raw_strs)).replace(' ', '').replace('\n', '') lenght = len(raw_strs) mid_lst = [] for i in range(lenght-2): mid_lst.append(raw_strs[i:i+3]) if len(set(mid_lst)) != len(mid_lst): print("NG") elif len(raw_strs) <8: print("NG") else: mid_dict = { 'dig':0 , "alpha_low":0 , "other":0 , "alpha_upper":0 } pattern_low = re.compile(r'([a-z]+)') pattern_upper = re.compile(r'([A-Z]+)') pattern_num = re.compile(r'(\d+)') if re.findall(pattern_low, raw_set): mid_dict["alpha_low"] += 1 raw_set = re.sub(pattern_low, "", raw_set) if re.findall(pattern_upper, raw_set): mid_dict["alpha_upper"] += 1 raw_set = re.sub(pattern_upper, "", raw_set) if re.findall(pattern_num, raw_set): mid_dict["dig"] += 1 raw_set = re.sub(pattern_num, "", raw_set) mid_len = len(raw_set) if len(raw_set)>0: mid_dict["other"] = mid_len if sum(i for i in mid_dict.values())>=3: print("OK") else: print("NG") except: break
def check_password(password:str):
#判断字符串长度
if len(password)<= 8:
return False
check_re = [0,0,0,0]
#使用四个判断来看符不符合“包括大小写字母.数字.其它符号,以上四种至少三种”条件 for letter in password: #一个一个字符遍历
if letter.isupper(): #判断是否有大写
check_re[0] = 1
elif letter.islower():#判断是否有小写
check_re[1] = 1
elif letter.isdigit(): #判断是否为数字
check_re[2] = 1
else: #判断是否有其他字符
check_re[3] = 1
if sum(check_re) < 3:
return False
#使用逐位增加,每次取三位,然后保存在字典dic里,然后每次取出来都进行判断字典dic里面you'w dic = {}
str_check = True
for i in range(len(password) - 2):
cut_str = password[i:i+3]
if cut_str in dic.keys():
#dic[cut_str] += 1
return False
else:
dic[cut_str] = 1
return True
while True:
try:
password = input()
if check_password(password):
print("OK")
else:
print("NG")
except:
break
import sys # 判断密码是否合法 def is_legal(str1): lst1 = list(str1) # pop掉最后一个换行符 lst1.pop() # 长度判断 if len(lst1) <= 8: return 'NG' # 公共子串判断 for i in range(len(lst1)-2): # 长度为3的子串, 重复出现则返回NG if str1[i:i+3] in str1[i+1:]: return 'NG' # 四种情况判断 kind_dict = {'dig': 0, 'upper': 0, 'lower': 0, 'other': 0} for i in lst1: # 数字 if i.isdigit(): kind_dict['dig'] = 1 # 大写字母 elif ord('Z') >= ord(i) and ord('A') <= ord(i): kind_dict['upper'] = 1 # 小写字母 elif ord('z') >= ord(i) and ord('a') <= ord(i): kind_dict['lower'] = 1 # 其他 else: kind_dict['other'] = 1 # 满足三种以上 if sum(list(kind_dict.values())) >= 3: return 'OK' else: return 'NG' # 读取 lines = list(sys.stdin.readlines()) for i in lines: print(is_legal(i))
while True: try: s = input() if len(s) <= 8: print('NG') else: a1 = 0 a2 = 0 a3 = 0 a4 = 0 active = False for i in range(len(s)): if s[i].isalpha(): if s[i].isupper(): a1 = 1 else: a2 = 1 elif s[i].isnumeric(): a3 = 1 elif s[i] != ' ' and s[i] != '\n': a4 = 1 if a1 + a2 + a3 + a4 >= 3: active = True break if not active: print('NG') else: se = set() for j in range(len(s) - 2): s1 = s[j:j+3] se.add(s1) # print(se) if len(se) <= len(s)-3: print('NG') else: print('OK') except: break
class Test: m = "!@#$%^&*()_-+=.?/|" l1 = [] while True: # try: try: s = input() except: break n = "OK" l = [False, False, False, False] if len(s) < 8: n = "NG" if n != "NG": for i in s: if i.islower(): l[0] = True if i.isupper(): l[1] = True if i.isnumeric(): l[2] = True if i in m: l[3] = True if l.count(True) < 3: n = "NG" if n != "NG": for i in range(0, len(s) - 2): for j in range(i + 2, int(len(s) / 2) + 1): if s.count(s[i:j+1]) > 1: # print(s[i:j+1]) n = "NG" break l1.append(n) for i in l1: print(i)