牛客网学习笔记——中等题们(字符串)

HJ20 密码验证合格程序

牛客网学习笔记——中等题们(字符串)_第1张图片
牛客网学习笔记——中等题们(字符串)_第2张图片

def check(s):
    if len(s) <= 8:
        return 0
    la =lA = l1 = l_ = 0
    for i in range(len(s)):
        if 'a' <= s[i] <= 'z':
            la = 1
        elif 'A' <= s[i] <= 'Z':
            lA = 1
        elif '0' <= s[i] <= '9':
            l1 = 1
        else:
            l_ = 1
    if la + lA + l1 + l_ < 3:
        return 0
    for i in range(len(s)-3):
        a = list(s.split(s[i:i+3]))
        if len(a) >= 3:
            return 0
    return 1

while True:
    try:
        s = input()
        if check(s) == 0:
            print('NG')
        else:
            print('OK')
    except:
        break

HJ26 字符串排序

牛客网学习笔记——中等题们(字符串)_第3张图片
牛客网学习笔记——中等题们(字符串)_第4张图片

sorted(a, key=str.upper)
while True:
    try:
        s = input()
        a = ''
        for i in s:
            if i.isalpha():
                a += i
        b = sorted(a, key=str.upper)
        index = 0
        d = ''
        for i in s:
            if i.isalpha():
                d = d + b[index]
                index += 1
            else:
                d = d + i
        print(d)
    except:
        break

你可能感兴趣的:(学习记录,学习)