zoukankan      html  css  js  c++  java
  • 牛客网编程练习(华为机试在线训练)-----密码验证合格程序

    题目描述

    密码要求:

    1.长度超过8位

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

    3.不能有相同长度超2的子串重复

    说明:长度超过2的子串

    输入描述:

    一组或多组长度超过2的子符串。每组占一行

    输出描述:

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

    示例1

    输入

    021Abc9000
    021Abc9Abc1
    021ABC9000
    021$bc9000
    

    输出

    OK
    NG
    NG
    OK

    Python code:

    def fun1(str):
        if len(str) > 8:
            return 1
        else:
            return 0
    
    def fun2(str):
        num1 = 0
        num2 = 0
        num3 = 0
        num4 = 0
        for i in str:
            if 'a'<=i and i<='z':
                num1 = 1
            elif 'A' <=i and i<='Z':
                num2 = 1
            elif '0' <=i and i<='9':
                num3 = 1
            else:
                num4 = 1
        if (num1+num2+num3+num4) >=3:
            return 1
        else:
            return 0
    
    def fun3(str):
        for i in range((len(str)-3)):
            if str[i:i+3] in str[i+1:]:
                return 0
                break
        return 1
    
    while True:
        try:
            str1 = input()
            if fun1(str1) and fun2(str1) and fun3(str1):
                print('OK')
            else:
                print('NG')
        except:
            break

    思路:将每个条件单独考虑,写成一个个函数。不定多少组输入时,用while循环。

  • 相关阅读:
    jmeter之正则表达式
    python_appium搭建APP自动化测试环境
    网络编程
    四种单例模式
    Pycharm快捷键
    面向对象
    阶段性总结
    模块之numpy,pandas,matplotlib
    模块之json,pickle,os,sys,logging
    模块之Time,datatime,hashlib,hmac
  • 原文地址:https://www.cnblogs.com/xiaotongtt/p/10796912.html
Copyright © 2011-2022 走看看